1,布局文件 跟布局为drawerLayout 先写的是主布局 后写的是侧拉清单布局
<android.support.v4.widget.DrawerLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/dl"> //主布局 <FrameLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/fl"> </FrameLayout>//侧拉 <RelativeLayout android:id="@+id/dra" android:background="#ffffff" android:layout_gravity="left" android:layout_width="match_parent" android:layout_height="200dp"> <ImageView android:id="@+id/tou" android:layout_centerHorizontal="true" android:layout_width="100dp" android:layout_height="100dp" android:src="@mipmap/ic_launcher"/> <ListView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/lv" android:layout_below="@+id/tou"></ListView> </RelativeLayout> </android.support.v4.widget.DrawerLayout>2. oncreate中 根据id获得所有布局 DrawerLayout 主布局侧拉布局//listview添加适配器 final String[] titles={"头条","社会","财经","国内","军事"}; //默认显示第一个 Myfragement myfragement=new Myfragement(); Bundle bundle=new Bundle(); bundle.putString("name",titles[0]); myfragement.setArguments(bundle); getSupportFragmentManager().beginTransaction().replace(R.id.fl,myfragement).commit(); lv.setAdapter(new ArrayAdapter<String>(MainActivity.this,android.R.layout.simple_list_item_1,a ndroid.R.id.text1, titles)); lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { //关闭侧滑 dl.closeDrawer(dra); Myfragement myfragement=new Myfragement(); Bundle bundle=new Bundle(); bundle.putString("name",titles[i]); myfragement.setArguments(bundle); getSupportFragmentManager().beginTransaction().replace(R.id.fl,myfragement).commit(); } });3.Myfragement中//动态加载fragement@Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle s avedInstanceState) { v = View.inflate(getActivity(), R.layout.fragement_layout, null); lv1 = (ListView)v.findViewById(R.id.lv1); return v; } //判断要展示的项 @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); String name= getArguments().getString("name", ""); if(name.equals("头条")){ name="toutiao"; }else if(name.equals("社会")){ name="shehui"; }else if(name.equals("财经")){ name="caijing"; }else if(name.equals("国内")){ name="guonei"; }else if(name.equals("军事")){ name="junshi"; } getDataFromNet(name); }4.Myadp中进行适配