实例效果图:
1.创建5个Fragment和布局。分别返回相应的布局registerfragment0,1,2,3,4,;
RegisterFragment0代码如下:
public class RegisterFragment0 extends Fragment{
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View registerfragment0 = inflater.inflate(R.layout.registerfragment0, null);
return registerfragment0;
}
}
2.在MainActivity布局文件中添加ViewPager,RadioGroup,和五个RadioButton;
代码如下:
<LinearLayout
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.zhiyuan3g.lipinhui.MainActivity">
<android.support.v4.view.ViewPager
android:layout_weight="9"
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/view"></android.support.v4.view.ViewPager>
<RadioGroup
android:layout_weight="1"
android:id="@+id/radio"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp">
<RadioButton
android:layout_weight="1"
android:textColor="#D81E06"
android:text="首页"
android:id="@+id/radiobtn_mian"
android:drawableTop="@drawable/maintrue"
android:gravity="center"
android:button="@null"
android:layout_width="wrap_content"
android:layout_height="match_parent"/>
<RadioButton
android:layout_weight="1"
android:text="附近"
android:drawableTop="@drawable/nearbyfalse"
android:gravity="center"
android:button="@null"
android:id="@+id/radiobtn_nearby"
android:layout_width="wrap_content"
android:layout_height="match_parent"/>
<RadioButton
android:layout_weight="1"
android:text="发现"
android:drawableTop="@drawable/findfalse"
android:gravity="center"
android:button="@null"
android:id="@+id/radiobtn_find&#