布局(权限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;
}
}
}