游标ViewPage+Fragment

xml布局

<RadioGroup
    android:id="@+id/radioGroup"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    >
    <RadioButton
        android:id="@+id/rad_but01"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="ANDROID"
        android:gravity="center"
        android:button="@null"
        android:padding="10dp"
        android:checked="true"
        android:layout_weight="1"
        />
    <RadioButton
        android:id="@+id/rad_but02"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="IOS"
        android:gravity="center"
        android:button="@null"
        android:padding="10dp"
        android:layout_weight="1"
        />
    <RadioButton
        android:id="@+id/rad_but03"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="福利"
        android:gravity="center"
        android:button="@null"
        android:padding="10dp"
        android:layout_weight="1"
        />
</RadioGroup>
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="5dp"
    android:orientation="horizontal"
    >
    <TextView
        android:id="@+id/rad_text1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#5b5959"
        android:layout_weight="1"
        />
    <TextView
        android:id="@+id/rad_text2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#5b5959"
        android:layout_weight="1"
        />
    <TextView
        android:id="@+id/rad_text3"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#5b5959"
        android:layout_weight="1"
        />

</LinearLayout>
<android.support.v4.view.ViewPager
    android:id="@+id/home_viewpager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    />
MainActivity
 txt1.setVisibility(View.VISIBLE);
    txt2.setVisibility(View.INVISIBLE);
    txt3.setVisibility(View.INVISIBLE);

    //将Fragment放入集合中
    list = new ArrayList<Fragment>();
    list.add(new Home_Android());
    list.add(new Home_Ios());
    list.add(new Home_Fuli());

    //设置FragmentPageAdapter适配器将Fragemnt添加
    viewPager.setAdapter(new FragmentPagerAdapter(getFragmentManager()) {
        @Override
        public Fragment getItem(int position) {
            return list.get(position);
        }

        @Override
        public int getCount() {
            return list.size();
        }
    });
    viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

        }

        @Override
        public void onPageSelected(int position) {
            switch (position){
                case 0:
                    radioGroup.check(R.id.rad_but01);
                    txt1.setVisibility(View.VISIBLE);
                    txt2.setVisibility(View.INVISIBLE);
                    txt3.setVisibility(View.INVISIBLE);
                    break;
                case 1:
                    radioGroup.check(R.id.rad_but02);
                    txt1.setVisibility(View.INVISIBLE);
                    txt2.setVisibility(View.VISIBLE);
                    txt3.setVisibility(View.INVISIBLE);
                    break;
                case 2:
                    radioGroup.check(R.id.rad_but03);
                    txt1.setVisibility(View.INVISIBLE);
                    txt2.setVisibility(View.INVISIBLE);
                    txt3.setVisibility(View.VISIBLE);
            }
        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    });
    radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {
            switch (checkedId){
                case R.id.rad_but01 :
                    viewPager.setCurrentItem(0);
                    break;
                case R.id.rad_but02 :
                    viewPager.setCurrentItem(1);
                    break;
                case R.id.rad_but03 :
                    viewPager.setCurrentItem(2);

            }
        }
    });
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值