TabLayout+滑动+网络展示

public class MainActivity extends FragmentActivity {

    private ViewPager vp;
    private TabLayout tablayout;
    private List<Fragment> list;
    private String str[] = new String[]{"题目一", "题目二", "题目三","题目四"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    private void initView() {
//使用适配器将ViewPager与Fragment绑定在一起
        vp = (ViewPager) findViewById(R.id.vp);
//添加数据
        listadd();
        Vpadapter adapter = new Vpadapter(getSupportFragmentManager());
        vp.setAdapter(adapter);
//将TabLayout与ViewPager绑定在一起
        tablayout = (TabLayout) findViewById(R.id.tablayout);
//绑定
        tablayout.setupWithViewPager(vp);
//字体颜色
        tablayout.setTabTextColors(getResources().getColor(R.color.black), getResources().getColor(R.color.hui));
//指示器颜色(选中状态下划线的颜色)
        tablayout.setSelectedTabIndicatorColor(getResources().getColor(R.color.hui));
//模式
        tablayout.setTabMode(TabLayout.MODE_SCROLLABLE);
    }

    private void listadd() {
        list = new ArrayList<>();
        list.add(new One());
        list.add(new Two());
        list.add(new Three());
        list.add(new Four());
    }

    class Vpadapter extends FragmentPagerAdapter {

        @Override
        public CharSequence getPageTitle(int position) {
            return str[position];
        }

        public Vpadapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return list.get(position);
        }

        @Override
        public int getCount() {
            return list.size();
        }
    }
}

    private void listadd() {
        list = new ArrayList<>();
        list.add(new One());
        list.add(new Two());
        list.add(new Three());
        list.add(new Four());
    }

    class Vpadapter extends FragmentPagerAdapter {

        @Override
        public CharSequence getPageTitle(int position) {
            return str[position];
        }

        public Vpadapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return list.get(position);
        }

        @Override
        public int getCount() {
            return list.size();
        }
    }
}





    <android.support.design.widget.TabLayout
        android:id="@+id/tablayout"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        >
    </android.support.design.widget.TabLayout>

    <com.youth.banner.Banner
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="3"
        android:id="@+id/banner"
        ></com.youth.banner.Banner>
        <android.support.v4.view.ViewPager
         android:id="@+id/vp"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="5"
            android:layout_alignParentBottom="true"
            android:layout_alignParentStart="true">
        </android.support.v4.view.ViewPager>
    <LinearLayout

        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="horizontal"
        >
        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:layout_marginTop="20dp"
            android:textSize="15sp"
            android:text="技术"
            />
        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:layout_marginTop="20dp"
          
            android:textSize="15sp"
            android:text="资讯"
            />
        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:layout_marginTop="20dp"
            android:textSize="15sp"
            android:text="学园"
            />
        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:layout_marginTop="20dp"
            android:textSize="15sp"
            android:text="我的"
            />
    </LinearLayout>
</LinearLayout>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值