2

我有一個ViewPager有3個片段。當碎片對用戶可見時,它們中的每一個都包含相同的視圖和視圖。我正在重寫setUserVisibleHint來啓動動畫。當我滑動到碎片時,視圖仍然存在一秒鐘,然後消失,然後開始動畫。 我想完全刪除它們不可見時的視圖,並且在滑動到片段時它們變得可見並且動畫開始。 基本上我試圖在參數爲false時將它們隱藏在setUserVisibleHint中。這什麼都不做。即使片段不可見,視圖仍然可見。ViewPager查看可見性問題

回答

0

試試這個,

你應該使用ViewPager與Tablayout使這種在這種情況下不發生問題......

請參考以下鏈接,

public class ViewPagerAdapter extends FragmentStatePagerAdapter { 

    public ViewPagerAdapter(FragmentManager fm) { 
     super(fm); 
    } 

    @Override 
    public Fragment getItem(int position) { 
     return new TabFragment(); // Which Fragment should be dislpayed by the viewpager for the given position 
            // In my case we are showing up only one fragment in all the three tabs so we are 
            // not worrying about the position and just returning the TabFragment 
    } 

    @Override 
    public int getCount() { 
     return 3;   // As there are only 3 Tabs 
    } 

} 

http://www.android4devs.com/2015/12/tab-layout-material-design-support.html

我希望它能幫助你...