安卓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.圖片