VerticalTabLayout

雍骏俊
2023-12-01

布局:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    >
    <q.rorbin.verticaltablayout.VerticalTabLayout
        android:layout_width="50dp"
        android:layout_height="match_parent"
        android:id="@+id/tab"
        app:tabGravity="center"
        app:tabIndicatorColor="@color/colorAccent"
        app:tabMode="scrollable"
        app:tabSelectedTextColor="@color/colorPrimaryDark"
        app:tabTextColor="@color/colorPrimary"
        ></q.rorbin.verticaltablayout.VerticalTabLayout>

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

代码:

tab = (VerticalTabLayout) findViewById(R.id.tab);//得到verticalTablayout的ID
vp = (ViewPager) findViewById(R.id.vp);//得到viewpager的ID
 mypager = new Mypager(getSupportFragmentManager());//适配器
vp.setAdapter(mypager);//绑定
tab.setupWithViewPager(vp);//绑定

适配器:
class Mypager extends FragmentPagerAdapter{

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

    @Override
    public Fragment getItem(int position) {
        Fragment instance = Frag.getInstance(datas.get(position));
        return instance;
    }

    @Override
    public int getCount() {
        return datas.size();
    }
    @Override
    public CharSequence getPageTitle(int position) {
        return datas.get(position);
    }
}


 类似资料:

相关阅读

相关文章

相关问答