【android】TabLayout文字闪烁问题

安卓MD设计提供了一个非常酷炫的效果,TabLayout拿来做选项卡时非常合适的,但是在实际使用中发现22.2.1版本号的TabLayout在ViewPager滑动的时候会出现闪烁现象。

解决方法:在gradle文件里

1:要么升级到23.x(compile 'com.android.support:design:23.1.1')

2:要么使用22.0里最后一个没有bug的版本(compile 'com.android.support:design:22.2.0')

 

以上只是针对tabLayout文字闪烁的情况,如果图片闪烁要么升级到23.x

要么请参考以下方式自行解决,来源http://stackoverflow.com/questions/31828610/why-do-the-tablayouts-tabs-icons-texts-blink-when-swiping-between-pages

use the old version (22.2.0) as I've mentioned above.

you need to avoid using selectors for the icons. Use the exact image resource ids instead:

private static final int[] TAB_ICONS_UNSELECTED = {... };
private static final int[] TAB_ICONS_SELECTED = {... };

 

update the icons based on the page selections, as such:

mViewPager.addOnPageChangeListener(new OnPageChangeListener() {
@Override
public void onPageSelected(final int position) {
for (int i = 0; i < tabLayout.getTabCount(); ++i)
tabLayout.getTabAt(i).setIcon(i != position ? TAB_ICONS_UNSELECTED[i] : TAB_ICONS_SELECTED[i]);
}
});

 

Also, remember to call about the same loop when initializing the TabLayout. Something like that:

for (int i = 0; i < tabLayout.getTabCount(); ++i)
tabLayout.getTabAt(i).setIcon(i != mViewPager.getCurrentItem() ? TAB_ICONS_UNSELECTED[i] : TAB_ICONS_SELECTED[i]);

I think that this should also fix the issue for texts and not just icons.

 

转载于:https://www.cnblogs.com/kimmy/p/5073144.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值