实例—ViewPager+RadioGroup实现底部导航栏和页面的滑动

通过ViewPager+RadioGroup实现了底部导航栏和页面的滚动
摘要由CSDN通过智能技术生成

实例效果图:


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&#

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值