我有一个包含4个片段的活动,在每个片段中,我有一个线程,4个片段一起启动,但我需要在它们之间滑动,以便每个片段都可见,我想知道的是,如何只留下正在查看的片段的线程,并中断其他片段,当你滑向其他片段时,同样的东西会启动一个线程并中断其他片段
适配器
public TabManualAdapter(@NonNull FragmentManager fm) {
super(fm);
}
@NonNull
@Override
public Fragment getItem(int position) {
Fragment fragment = null;
switch (position){
case 0 :
fragment = new Fragment1();
break;
case 1 :
fragment = new Fragment2();
break;
case 2:
fragment = new Fragment3();
break;
case 3:
fragment = new Fragment4();
break;
}
return fragment;
}
@Override
public int getCount() {
return tituloTabsManual.length;
}
@Nullable
@Override
public CharSequence getPageTitle(int position) {
return tituloTabsManual[position];
}
}
主机活动:
viewPager.setPageTransformer(true,new ZoomOutPageTransformer());
viewPager.setOffscreenPageLimit(4);
slidingTabLayout.setSelectedIndicatorColors(ContextCompat.getColor(this,R.color.colorPrimary));
slidingTabLayout.setDistributeEvenly(true);
slidingTabLayout.setBackgroundColor( ContextCompat.getColor( this, R.color.black ) );
TabManualAdapter tabManualAdapter = new TabManualAdapter(getSupportFragmentManager());
viewPager.setAdapter(tabManualAdapter);
暂无答案!
目前还没有任何答案,快来回答吧!