studio android tv,TvTabLayout TvTabLayout 针对 Android Tv 端把原生的 tablayout 进行适配和改造 @codeKK Android开源站...

针对 TV 端的特性对 TabLayout 进行了适配与开发;

支持图片或颜色值作为 Indicator;

效果

5cbbe2da84e3e2355177634c96a81c96.gif

Android Studio 集成

// support 版本

implementation 'com.owen:tv-tablayout:1.0.4'

// androidx 版本

implementation 'com.owen:tv-tablayout:2.0.0'

自定义属性

属性

值/类型

简介

tabIndicatorResId

reference

指示器的资源(图片或颜色)

tabIndicatorWidth

dimension

指示器的宽

tabIndicatorHeight

dimension

指示器的高

tabIndicatorGravity

top / center / bottom

指示器的位置

tabIndicatorBackgroundHeight

dimension

指示器背景高度

tabIndicatorBackgroundColor

color

指示器背景颜色

tabContentStart

dimension

内容开始距离

tabContentBottom

dimension

内容底部距离

tabCircleDotRadius

dimension

小圆点的半径

tabCircleDotColor

color / reference

小圆点的颜色

tabScrollMode

scrollable / fixed

滚动模式

tabBackground

reference

tab 背景

tabGravity

top / center / bottom / fill

tab 的位置

tabMinWidth

dimension

tab 最小宽度

tabMaxWidth

dimension

tab 最大宽度

tabTexSize

dimension

文本大小

tabTextColor

color / reference

文本颜色

tabTextSelectedScale

float

文本选中时的缩放比例

tabTextSelectedCentered

boolean

文本选中时是否居中

tabPaddingStart

dimension

tab padding start

tabPaddingTop

dimension

tab padding top

tabPaddingEnd

dimension

tab padding end

tabPaddingBottom

dimension

tab padding bottom

tabPadding

dimension

tab padding

使用

// 代码动态添加 tab

TvTabLayout mTabLayout = findViewById(R.id.tablayout);

for(int i=0; i<15; i++) {

mTabLayout.addTab(mTabLayout.newTab().setText("标题"+i), i == 0);

}

// 布局直接指定 tab

android:id="@+id/tablayout3"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginTop="60dp"

app:tabIndicatorResId="@drawable/zx_p1_light"

app:tabIndicatorWidth="108dp"

app:tabIndicatorHeight="15dp"

app:tabIndicatorBackgroundColor="@color/color_88ff804B"

app:tabIndicatorBackgroundHeight="3dp"

app:tabMinWidth="160dp"

app:tabScrollMode="fixed"

app:tabGravity="center"

app:tabPaddingBottom="12dp"

app:tabTextSelectedScale="1.2"

app:tabTexSize="22sp"

app:tabTextColor="@drawable/selector_tab_font_color">

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="标题 1"/>

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="标题 2"/>

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="标题 3"/>

// 监听设置

mTabLayout.addOnTabSelectedListener(new TvTabLayout.OnTabSelectedListener() {

@Override

public void onTabSelected(TvTabLayout.Tab tab) {

}

@Override

public void onTabUnselected(TvTabLayout.Tab tab) {

}

@Override

public void onTabReselected(TvTabLayout.Tab tab) {

}

});

更详细的使用请见 exmaple

其它作品

TvRecyclerView 框架TvRecyclerView

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值