Android学习笔记十八之TabLayout标签布局
AbsoluteLayout绝对布局,在API13中被废弃了,采用FrameLayout, RelativeLayout or a custom layout 替代,所以就不在介绍AbsoluteLayout绝对布局,我们介绍一个Google推出的新的布局——TabLayout标签布局。
TabLayout标签布局是Google 2015年IO大会推出的Android Support Design库中的一个控件,继承于HorizontalScrollView,实现的效果跟ViewPage和ViewpageIndicator实现的效果差不多。不过这个是官方推出的,更加符合Google的MD设计理念。对于Tablayout,Google官方是这样解析的:
You should set a listener via setOnTabSelectedListener(OnTabSelectedListener) to be notified when any tab’s selection state has been changed.If you’re using a ViewPager together with this layout, you can call setupWithViewPager(ViewPager) to link the two together. This layout will be automatically populated from the PagerAdapter’s page titles.
简单翻译就是:
为选项卡的状态改变设置一个setOnTablSelectedListener(OnTabSelectedListener) ,如果在布局中使用ViewPager,你可以使用setupWithViewPager(ViewPager)来给PagerAdapter设置page title和关联viewpager和TabLayout.
TabLayout的属性:
- android.support.design:tabBackground属性:设置标签的背景
- android.support.design:tabContentStart属性:从标签应位于的起始边缘的Y轴上的位置。
- android.support.design:tabGravity属性:对齐,对应java方法是:setTabGravity(int),其中center对应是1,fill对应是0;
- android.support.design:tabIndicatorColor属性:设置当前选定的标签的指示器的颜色。对应java方法是setSelectedTabIndicatorColor(int);
- android.support.design:tabIndicatorHeight属性:设置当前被