侧滑菜单

侧滑布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/cehuabeijing"
    android:clickable="true"
    android:orientation="vertical">


    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:scrollbars="none">


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/cehuabg"


                android:orientation="vertical"
                android:paddingBottom="20dp">


                <de.hdodenhof.circleimageview.CircleImageView xmlns:app="http://schemas.android.com/apk/res-auto"
                    android:id="@+id/iv_cehua_touxiang"
                    android:layout_width="130dp"
                    android:layout_height="130dp"
                    android:layout_gravity="center_horizontal"
                    android:layout_marginTop="40dp"
                    app:civ_border_color="#ffffff"
                    app:civ_border_width="1dp" />




                <TextView
                    android:id="@+id/tv_cehua_phone"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_horizontal"
                    android:layout_marginTop="10dp"
                    android:textColor="#ffffff"
                    android:textSize="20sp"
                    android:textStyle="bold" />


                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_horizontal">


                    <TextView
                        android:id="@+id/tv_cehua_huiyuan"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="10dp"
                        android:textColor="#ffffff"
                        android:textSize="20sp"
                        android:textStyle="bold"
                        android:visibility="gone"
                        android:layout_gravity="center_horizontal"/>
                </LinearLayout>
            </LinearLayout>


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="18dp"
                android:orientation="horizontal">


                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:layout_marginLeft="18dp"
                    android:background="@drawable/cehuaqianbao" />


                <TextView
                    android:id="@+id/tv_cehua_qianbao"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:layout_marginLeft="12dp"
                    android:background="#ffffff"
                    android:text="@string/tv_cehua_qianbao"
                    android:textSize="18sp" />


            </LinearLayout>




            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="20dp"
                android:orientation="horizontal">


                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:layout_marginLeft="18dp"
                    android:background="@drawable/cehuadingdan" />


                <TextView
                    android:id="@+id/tv_cehua_dingdan"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:layout_marginLeft="12dp"
                    android:background="#ffffff"
                    android:text="@string/tv_cehua_dingdan"
                    android:textSize="18sp" />


            </LinearLayout>




            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="20dp"
                android:orientation="horizontal">


                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:layout_marginLeft="18dp"
                    android:background="@drawable/cehua_car" />


                <TextView
                    android:id="@+id/tv_cehua_aiche"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:background="#ffffff"
                    android:paddingLeft="12dp"
                    android:text="@string/tv_cehua_aiche"
                    android:textSize="18sp" />


            </LinearLayout>


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="20dp"
                android:orientation="horizontal">


                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:layout_marginLeft="18dp"
                    android:background="@drawable/cehuashezhi" />


                <TextView
                    android:id="@+id/tv_cehua_shezhi"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:background="#ffffff"
                    android:paddingLeft="12dp"
                    android:text="@string/tv_cehua_shezhi"
                    android:textSize="18sp" />


            </LinearLayout>


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="20dp"
                android:orientation="horizontal">


                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:layout_marginLeft="18dp"
                    android:background="@drawable/cehua_bangzhu" />


                <TextView
                    android:id="@+id/tv_cehua_bangzhu"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:paddingLeft="12dp"
                    android:text="@string/tv_cehua_bangzhu"
                    android:textSize="18sp" />


            </LinearLayout>
            <!--<LinearLayout-->
                <!--android:layout_width="match_parent"-->
                <!--android:layout_height="wrap_content"-->
                <!--android:layout_marginTop="20dp"-->
                <!--android:orientation="horizontal">-->


                <!--<ImageView-->
                    <!--android:layout_width="wrap_content"-->
                    <!--android:layout_height="wrap_content"-->
                    <!--android:layout_gravity="center_vertical"-->
                    <!--android:layout_marginLeft="18dp"-->
                    <!--android:background="@drawable/cehua_bangzhu" />-->
                <!--<TextView-->
                    <!--android:id="@+id/tv_cehua_gengxin"-->
                    <!--android:layout_width="match_parent"-->
                    <!--android:layout_height="wrap_content"-->
                    <!--android:layout_gravity="center_vertical"-->
                    <!--android:paddingLeft="12dp"-->
                    <!--android:text="检查更新"-->
                    <!--android:textSize="18sp" />-->


            <!--</LinearLayout>-->
        </LinearLayout>
    </ScrollView>


</LinearLayout>
在Activity布局添加


    <!--侧滑菜单-->
    <LinearLayout
        android:layout_width="250dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@android:color/white">
        <include layout="@layout/item_cehua"/>
    </LinearLayout>
</android.support.v4.widget.DrawerLayout>//尾标签
在activity 的 oncreate中添加
 initViews();
        //获取侧滑对象内容
        initCehuaViews();
        //侧滑菜单监听设置
        setDraweLayout();
        //获取BaiduMap对象




 private void showDrawerLayout() {
        if (!drawerLayout.isDrawerOpen(Gravity.LEFT)) {
            drawerLayout.openDrawer(Gravity.LEFT);
        } else {
            drawerLayout.closeDrawer(Gravity.LEFT);
        }
        drawerLayout.closeDrawer(Gravity.LEFT);
    }
    private void initViews() {
        //获取地图控件引用
        mMapView = (MapView) findViewById(R.id.bdmapView);
        workers = new ArrayList<>();
        //记录当前Maker标记位置的地理信息
        cheliangweizhi = (TextView) findViewById(R.id.tv_main_cheliangweizhi);
        //获取控件
        iv_touxiang = (CircleImageView) findViewById(R.id.iv_main_touxiang);
        xiche = (Button) findViewById(R.id.btn_main_xiche);
        baoxian = (Button) findViewById(R.id.btn_main_baoxian);
        weizhang = (Button) findViewById(R.id.btn_main_weizhang);
        ib_shuaxin = (ImageButton) findViewById(R.id.ib_main_shuaxin);
        rl_xiaoxi_tongzhi = (RelativeLayout) findViewById(R.id.rl_xiaoxi_tongzhi);
        tv_new_msg=(TextView)findViewById(R.id.tv_new_msg);
        xiche.setOnClickListener(this);
        baoxian.setOnClickListener(this);
        weizhang.setOnClickListener(this);
        ib_shuaxin.setOnClickListener(this);
        iv_touxiang.setOnClickListener(this);
        rl_xiaoxi_tongzhi.setOnClickListener(this);
    }
 private void initCehuaViews() {
        drawerLayout = (DrawerLayout) findViewById(R.id.dl_left);
        iv_cehua_touxiang = (CircleImageView) findViewById(R.id.iv_cehua_touxiang);
        tv_cehua_yonghuming = (TextView) findViewById(R.id.tv_cehua_phone);
        tv_cehua_huiyuan = (TextView) findViewById(R.id.tv_cehua_huiyuan);
        tv_cehua_qianbao = (TextView) findViewById(R.id.tv_cehua_qianbao);
        tv_cehua_dingdan = (TextView) findViewById(R.id.tv_cehua_dingdan);
        tv_cehua_aiche = (TextView) findViewById(R.id.tv_cehua_aiche);
        tv_cehua_shezhi = (TextView) findViewById(R.id.tv_cehua_shezhi);
        tv_cehua_bangzhu=(TextView)findViewById(R.id.tv_cehua_bangzhu);
//        tv_cehua_gengxin = (TextView) findViewById(R.id.tv_cehua_gengxin);
        iv_cehua_touxiang.setOnClickListener(this);
        tv_cehua_yonghuming.setOnClickListener(this);
        tv_cehua_huiyuan.setOnClickListener(this);
        tv_cehua_qianbao.setOnClickListener(this);
        tv_cehua_dingdan.setOnClickListener(this);
        tv_cehua_aiche.setOnClickListener(this);
        tv_cehua_shezhi.setOnClickListener(this);
        tv_cehua_bangzhu.setOnClickListener(this);
//        tv_cehua_gengxin.setOnClickListener(this);
//        tv_cehua_gengxin.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                String requestStri = "{\"code\":0,\"data\":{\"download_url\":\"http://wap.apk.anzhi.com/data3/apk/201512/20/55089e385f6e9f350e6455f995ca3452_26503500.apk\",\"force\":false,\"update_content\":\"测试更新接口\",\"v_code\":\"10\",\"v_name\":\"v1.0.0.16070810\",\"v_sha1\":\"7db76e18ac92bb29ff0ef012abfe178a78477534\",\"v_size\":12365909}}";
//                networkAutoUpdate(requestStri);
//            }
//        });
        xiche.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View view) {
                if (checkLogin()) {
                    checkCar(0);
                } else {
                    startLogin();
                }
            }
        });
        tv_cehua_bangzhu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                new AlertDialog.Builder(activity).setTitle("您确认拨打电话吗?")
//                        .setIcon(android.R.drawable.ic_dialog_info)
                        .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phone));
                                startActivity(intent);
                            }
                        })
                        .setNegativeButton("返回", null)
                        .show();
//              Intent intent=new Intent(MainActivity.this,TtsActivity.class);
//              startActivity(intent);
//
            }
//
        });
 private void setDraweLayout() {
        toggle = new ActionBarDrawerToggle(this, drawerLayout, R.string.drawer_open, R.string.drawer_close) {
            @Override
            public void onDrawerClosed(View drawerView) {
            }
            @Override
            public void onDrawerOpened(View drawerView) {
                if (checkLogin()) {
                    if (TextUtils.isEmpty(Contast.user.getU_Image())) {
                        Picasso.with(MainActivity.this).load(R.drawable.cehuamorentouxiang).into(iv_cehua_touxiang);
                    } else {
                        Uri image = Uri.parse(Contast.Domain + Contast.user.getU_Image());
                        Picasso.with(MainActivity.this).load(image)
                                .placeholder(R.drawable.cehuamorentouxiang)
                                .error(R.drawable.cehuamorentouxiang)
                                .into(iv_cehua_touxiang);
                    }
                    if (TextUtils.isEmpty(Contast.user.getU_Name())) {
                        tv_cehua_yonghuming.setText(Contast.user.getU_Tel());
                    } else {
                        tv_cehua_yonghuming.setText(Contast.user.getU_Name());
                    }
                    if (Contast.user.getU_Grade() == 1) {
                        tv_cehua_huiyuan.setText("普通会员");
                    } else if (Contast.user.getU_Grade() == 2) {
                        tv_cehua_huiyuan.setText("白金会员");
                    } else if (Contast.user.getU_Grade() == 3) {
                        tv_cehua_huiyuan.setText("钻石会员");
                    }
                    tv_cehua_yonghuming.setVisibility(View.VISIBLE);
                    tv_cehua_huiyuan.setVisibility(View.VISIBLE);
                } else {
                    //如果没有登录,则提示用户登录
                    Picasso.with(MainActivity.this).load(R.drawable.cehuamorentouxiang).into(iv_cehua_touxiang);
                    tv_cehua_yonghuming.setText("未登录");
                    tv_cehua_yonghuming.setVisibility(View.VISIBLE);
                    tv_cehua_huiyuan.setVisibility(View.INVISIBLE);
                }
            }
        };
        drawerLayout.setDrawerListener(toggle);
    }
//
        showDrawerLayout();
    }

猜你喜欢

转载自blog.csdn.net/ydc0128/article/details/80533178