安卓MD设计提供了一个很是酷炫的效果,TabLayout拿来作选项卡时很是合适的,可是在实际使用中发现22.2.1版本号的TabLayout在ViewPager滑动的时候会出现闪烁现象。android
1:要么升级到23.x(compile 'com.android.support:design:23.1.1')ide
2:要么使用22.0里最后一个没有bug的版本(compile 'com.android.support:design:22.2.0')oop
以上只是针对tabLayout文字闪烁的状况,若是图片闪烁要么升级到23.xgradle
要么请参考如下方式自行解决,来源http://stackoverflow.com/questions/31828610/why-do-the-tablayouts-tabs-icons-texts-blink-when-swiping-between-pagesthis
use the old version (22.2.0) as I've mentioned above.spa
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:code
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:blog
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.图片