1.首先写好Fragment布局,写权重
<android.support.v4.view.ViewPager
android:id="@+id/parg"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
<RadioGroup
android:id="@+id/radioGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
>
<RadioButton
android:id="@+id/radioButton1"
android:text="list展示"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:button="@null"
/>
<RadioButton
android:id="@+id/radioButton2"
android:text="grid展示"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:button="@null"
/>
</RadioGroup>
2.MainActivity,里写滑动点击
**记得写适配器**
ArrayList<Fragment> data = new ArrayList<Fragment>();
data.add(new FragList());
data.add(new FragGrid());
//适配器
final FragAdter adter = new FragAdter(getSupportFragmentManager(),data);