DrawerLayout侧拉并点击侧拉选项

布局(权限design)

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/drawerlayout"
    tools:context=".MainActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/fragment"
            />
    </LinearLayout>
    <LinearLayout
        android:id="@+id/Zuo_Layout"
        android:layout_width="200dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@color/colorAccent"
        android:orientation="vertical">
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:src="@mipmap/ic_launcher_round" />
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:gravity="center"
        android:text="LK" />
    <TextView
        android:id="@+id/yi"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="xListView" />
    <TextView
        android:id="@+id/er"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TabLayout" />
    </LinearLayout>
</android.support.v4.widget.DrawerLayout>

main

package com.example.zk2;

import android.os.Bundle;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.example.zk2.fragment.Frag_one;
import com.example.zk2.fragment.Frag_two;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private FrameLayout fragment;
    private TextView yi;
    private TextView er;
    private Frag_one one;
    private Frag_two two;
    private DrawerLayout drawerlayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initData();
        initView();
    }

    private void initData() {
        one = new Frag_one();
        two = new Frag_two();
    }

    private void initView() {
        fragment = (FrameLayout) findViewById(R.id.fragment);
        yi = (TextView) findViewById(R.id.yi);
        yi.setOnClickListener(this);
        er = (TextView) findViewById(R.id.er);
        er.setOnClickListener(this);
        drawerlayout = (DrawerLayout) findViewById(R.id.drawerlayout);
        drawerlayout.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.yi:
                getSupportFragmentManager().beginTransaction().replace(R.id.fragment, one).commit();
                drawerlayout.closeDrawers();
                break;
            case R.id.er:
                getSupportFragmentManager().beginTransaction().replace(R.id.fragment, two).commit();
                drawerlayout.closeDrawers();
                break;
        }
    }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值