方法一:
mTabLayout.post(new Runnable() {
@Override
public void run() {
mTabLayout.setupWithViewPager(mViewPager);
}
});
方法二:
if (ViewCompat.isLaidOut(mTabLayout)) {
mTabLayout.setupWithViewPager(mViewPager);
} else {
mTabLayout.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
mTabLayout.setupWithViewPager(mViewPager);
mTabLayout.removeOnLayoutChangeListener(this);
}
});
}
在Fragment中使用TabLayout,TabLayout不能正常显示的问题。
最新推荐文章于 2021-05-27 13:20:28 发布