实现思路:一个activity中添加2个fragment,左边的frgament继承自ListFragment,右边的frgament只是做布局UI上的改变直接继承自Fragment,当点击左边列表的某一项item右边的fragment显示对应的信息
MainActivity中布局文件xml中主要是放置两个FrameLayout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="horizontal"
tools:context="com.example.wuke02.listfragmentdemo.MainActivity">
<FrameLayout
android:id="@+id/left_fragment"
android:layout_width="80dp"
android:layout_height="match_parent"
android:background="@color/green">
</FrameLayout>
<FrameLayout
android:id="@+id/right_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:background="@color/blue"></FrameLayout>
</LinearLayout>
分别是给fragment分配显示空间大小。
MainActivity中需处理的逻辑是先添加左边的fragment: