VerticalTabLayout的使用


//添加依赖包

compile 'q.rorbin:VerticalTabLayout:1.2.5'

3. 属性说明

xml code 说明
app:indicator_color setIndicatorColor 指示器颜色
app:indicator_width setIndicatorWidth 指示器宽度
app:indicator_gravity setIndicatorGravity 指示器位置
app:indicator_corners setIndicatorCorners 指示器圆角
app:tab_mode setTabMode Tab高度模式
app:tab_height setTabHeight Tab高度
app:tab_margin setTabMargin Tab间距

//其他过程和Tablayout一样

//XML布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
<LinearLayout
    android:orientation="horizontal"
    android:layout_width="wrap_content"
    android:layout_height="match_parent">
    <q.rorbin.verticaltablayout.VerticalTabLayout
        android:layout_width="100dp"
        android:id="@+id/vtb"
        android:layout_height="match_parent">
    q.rorbin.verticaltablayout.VerticalTabLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/vtbvp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

    android.support.v4.view.ViewPager>

LinearLayout>
 
  
LinearLayout>

//我是显示在第三个Frament中
public class san extends Fragment {

    private View inflate;
    private VerticalTabLayout vtb;
    private List datas = new ArrayList();
    private ViewPager vtbvp;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        inflate = View.inflate(getActivity(), R.layout.three, null);
        return inflate;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        vtb = inflate.findViewById(R.id.vtb);
        vtbvp = inflate.findViewById(R.id.vtbvp);

        datas.add("推荐");
        datas.add("要闻");
        datas.add("娱乐");
        datas.add("科技");
        datas.add("汽车");
        datas.add("体育");
//适配器
        vpsp vpsp = new vpsp(getActivity().getSupportFragmentManager());
        vtbvp.setAdapter(vpsp);
进行关联
        vtb.setupWithViewPager(vtbvp);

    }

    class vpsp extends FragmentPagerAdapter {

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

        //返回选项卡的文本 ,,,添加选项卡
        @Override
        public CharSequence getPageTitle(int position) {
            return datas.get(position);
        }
        //创建fragment对象并返回
        @Override
        public Fragment getItem(int position) {
            vcount vcount = new vcount();
            Bundle bundle = new Bundle();
            bundle.putString("name",datas.get(position));
            vcount.setArguments(bundle);
            return vcount;        }
        //返回数量
        @Override
        public int getCount() {
            return datas.size();
        }
    }
}

//vcount的Framnet中得到文字.进行操作,就OK了

public class vcount extends Fragment {
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View inflate = View.inflate(getActivity(), R.layout.vcountlayout, null);
        TextView cte = inflate.findViewById(R.id.oo);
        Bundle arguments = getArguments();
        String name = arguments.getString("name");
        Log.e("chen", "onCreateView: ------" + name);
        cte.setText(name);
        return inflate;
    }
}




你可能感兴趣的:(基础)