VerticalTablayout—竖的tab栏

效果图

image

1.添加依赖

    //垂直的tablayout
    implementation 'q.rorbin:VerticalTabLayout:1.2.5'

2.xml文件中添加控件【VerticalTabLayout集合帧布局使用,fragment开启事物的方法,或者直接用竖着的ViewPager

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    tools:context=".ui.country.fragment.InternationalFragment">

    <q.rorbin.verticaltablayout.VerticalTabLayout
        android:id="@+id/tab"
        android:layout_width="@dimen/dp_100"
        android:layout_height="match_parent"
        android:background="@color/c_EAEAEA"
        app:indicator_width="@dimen/dp_2"
        app:tab_height="@dimen/dp_50"
        app:tab_mode="scrollable" />

    <FrameLayout
        android:id="@+id/fl_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</LinearLayout>

3.代码简单使用

            mTab.setTabAdapter(new TabAdapter() {
            //设置个数
            @Override
            public int getCount() {
                return list.size();
            }

            @Override
            public ITabView.TabBadge getBadge(int position) {
                return null;
            }

            @Override
            public ITabView.TabIcon getIcon(int position) {
                return null;
            }
            //给tab栏设置标题
            @Override
            public ITabView.TabTitle getTitle(int position) {
                ITabView.TabTitle title = new ITabView.TabTitle.Builder()
                        .setContent(list.get(position).getName())
                        .setTextColor(Color.RED,Color.BLACK)
                        .build();
                return title;
            }
          //设置背景
            @Override
            public int getBackground(int position) {
                return 0;
            }
        });

  1. 属性说明
    app:indicator_color 指示器颜色
    app:indicator_width 指示器宽度
    app:indicator_gravity 指示器位置
    app:indicator_corners 指示器圆角
    app:tab_mode Tab高度模式
    app:tab_height Tab高度
    app:tab_margin Tab间距
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容