Android Studio 第五十期 - 自定义TabLayout

    代码已经整理好,效果如下图:

    code1:

 <com.ui.widget.UnAnimTabLayout
                android:id="@+id/tab"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_gravity="center_vertical"
                android:clipToPadding="false"
                android:paddingLeft="5dp"
                app:tabBackground="@drawable/tab_selector_green"
                app:tabIndicatorColor="@android:color/white"
                app:tabIndicatorHeight="0dp"
                app:tabMaxWidth="0dp"
                app:tabMinWidth="0dp"
                app:tabMode="scrollable"
                app:tabSelectedTextColor="@color/white"
                app:tabTextAppearance="@style/tab_text_size"
                app:tabTextColor="@color/black_common" />



    <style name="tab_text_size">
        <item name="android:textSize">28dp</item>
    </style>



 <com.widget.UnAnimTabLayout
                android:id="@+id/tab_add"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:clipToPadding="false"
                android:layout_marginLeft="@dimen/x20"
                android:layout_marginRight="@dimen/x20"
                app:tabIndicatorColor="@color/blue3"
                app:tabIndicatorHeight="@dimen/x3"
                app:tabMaxWidth="0dp"
                app:tabMinWidth="0dp"
                app:tabMode="scrollable"
                app:tabSelectedTextColor="@color/blue3"
                app:tabTextAppearance="@style/tab_text_size"
                app:tabTextColor="@color/black_common" />

    code2

 mCateTabLayout.addOnTabSelectedListener(new TabSelectAdapter() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                TabUtils.tabSelect(mCateTabLayout, tab);
                int tag = (int) tab.getTag();
                if (tag == -1) {
                    return;
                }
                if (!once_footer) {
                    once_footer = true;
                    return;
                }
                footer_id = tag;
                //请求数据bufen
                set_refresh_data();
            }
        });
        mCateTabLayout.post(new Runnable() {
            @Override
            public void run() {
                TabUtils.setIndicator(mCateTabLayout, 80, 80);
            }
        });


// 初始化

 tab_add.removeAllTabs();

for (FmNewFoodFenleiBean item : list_tab_add) {
            tab_add.addTab(tab_add.newTab()
                    .setTag(item.getFood_category_id()).setText(item.getFood_category_name()));
        }

    图片1:

    wKiom1mvlj2TBRHhAAB3QclvF_c872.png

    图片2:

    wKiom1mvlvPSsYmRAADI05Pj1RA222.png

    图片3:

    wKiom1mvlyKR8puHAAAkIRTkBLY502.png

    地址:https://github.com/geeklx/MyApplication/tree/master/p036_tablayoutdemo

    

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值