代码已经整理好,效果如下图:
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:
图片2:
图片3:
地址:https://github.com/geeklx/MyApplication/tree/master/p036_tablayoutdemo