Android Studio 第五十期 - 自定义TabLayout

简介:

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

    code1:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
  <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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
  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









本文转自 吴雨声 51CTO博客,原文链接:http://blog.51cto.com/liangxiao/1963094,如需转载请自行联系原作者

目录
相关文章
|
3天前
|
存储 Linux 开发工具
Linux手动升级替换Android Studio
【6月更文挑战第22天】
|
3天前
|
Android开发
Android Studio(2022.3.1)设置阿里云源-新旧版本
Android Studio(2022.3.1)设置阿里云源-新旧版本
13 1
|
6天前
|
XML Java 开发工具
Android Studio开发Android TV
【6月更文挑战第19天】
|
9天前
|
Android开发
Android studio 出现Plugin [id: ‘com.android.application‘, version: ‘8.1.0‘, apply: false] 问题解决办法
Android studio 出现Plugin [id: ‘com.android.application‘, version: ‘8.1.0‘, apply: false] 问题解决办法
78 1
|
1天前
|
Android开发
Android自定义View之正方形
【6月更文挑战第23天】
|
2天前
|
搜索推荐 Android开发 开发者
Android 自定义组件
Android 自定义组件
6 0
|
5天前
|
Android开发
如何 将Android Studio升级至最新版(4.0)
如何 将Android Studio升级至最新版(4.0)
9 0
|
6天前
|
Java 开发工具 Android开发
Android Studio 导出JavaDoc文档
Android Studio 导出JavaDoc文档
9 0
|
8天前
|
开发工具 Android开发
Android studio历史版本下载
Android studio历史版本下载
30 0
|
8天前
|
开发工具 Android开发
Android 代码自定义drawble文件实现View圆角背景
Android 代码自定义drawble文件实现View圆角背景
15 0