BackFragment.java
BaseBackFragment extends SwipeBackFragment;
public class BackFragment extends BaseBackFragment {
@Override
public int getContentViewId() {
return R.layout.home_layout;
}
@Override
protected void initAllMembersView(Bundle savedInstanceState) {
}
@Override
protected void onEnterAnimationEnd(Bundle savedInstanceState) {
super.onEnterAnimationEnd(savedInstanceState);
// 入场动画结束后执行 优化,防动画卡顿
}
@Override
public void onDestroyView() {
super.onDestroyView();
}
public static BackFragment newInstance() {
Bundle args = new Bundle();
BackFragment fragment = new BackFragment();
fragment.setArguments(args);
return fragment;
}
}
public class ManiFragment extends BaseFragment {
@BindView(R.id.viewpager)
ViewPager viewPager;
@BindView(R.id.bottom_bar)
SmartTabLayout bottomBar;
String[] tabNames = new String[]{"首页","发现", "我的"};
int[] tabIcons = new int[]{R.drawable.home_selector,R.drawable.home_selector, R.drawable.my_selector};
@Override
public int getContentViewId() {
return R.layout.main_layout;
}
@Override
protected void initAllMembersView(Bundle savedInstanceState) {
FragmentPagerItems pages = new FragmentPagerItems(getContext());
for (int i = 0; i < tabNames.length; i++) {
if(i == 1){
pages.add(FragmentPagerItem.of(tabNames[i],tabIcons[i], MyFragment.class));
}else{
pages.add(FragmentPagerItem.of(tabNames[i],tabIcons[i], HomeFragment.class));
}
}
bottomBar.setCustomTabView(new ImageTextTabProvider(getContext()));
FragmentPagerItemAdapter adapter = new FragmentPagerItemAdapter(
getFragmentManager(), pages);
viewPager.setAdapter(adapter);
bottomBar.setViewPager(viewPager);
RxBus.get().register(this);
}
@Override
public void onDestroyView() {
super.onDestroyView();
RxBus.get().unregister(this);
}
public static ManiFragment newInstance() {
Bundle args = new Bundle();
ManiFragment fragment = new ManiFragment();
fragment.setArguments(args);
return fragment;
}
@Subscribe
public void onStartFragment(StartBrotherEvent event){
start(event.targetFragment);
}
@Override
public FragmentAnimator onCreateFragmentAnimator() {
// 设置横向(和安卓4.x动画相同)
return new DefaultHorizontalAnimator();
}
BackFragment.java BaseBackFragment extends SwipeBackFragment; public class BackFragment extends BaseBackFragment { @Override public int getContentViewId() { return R.layout.home_layout; }
}
public class ManiFragment extends BaseFragment {
}