我有2个片段的ViewPager NonSwipeable(无法刷卡)。在第二个片段中,我使用Tab Indicator设置了正常的ViewPager(可以滑动)。但是,当我刷那个ViewPager时,它的外观滞后。
家长活动
public NonSwipeableViewPager mPager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);y;
setContentView(R.layout.activity_search);
....
mAdapter = new FragmentSearchAdapter(getSupportFragmentManager(), SearchActivity.this);
mAdapter.addFragment("search histori");
mAdapter.addFragment("search result");
mPager.setAdapter(mAdapter);
mPager.setOffscreenPageLimit(2);
....
}
这是Custom ViewPager NonSwipeable:
public class NonSwipeableViewPager extends ViewPager {
public NonSwipeableViewPager(Context context) {
super(context);
}
public NonSwipeableViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
// Never allow swiping to switch between pages
return false;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
// Never allow swiping to switch between pages
return false;
}
}
第二片段
@Bind(R.id.pager)
public ViewPager mPager;
@Bind(R.id.tabs)
PagerSlidingTabStrip mPagerSlidingTabStrip;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
if (container == null) {
return null;
}
View rootView = inflater.inflate(R.layout.fragment_search_result2, container, false);
mAdapter = new FragmentSearchResultAdapter(getActivity().getSupportFragmentManager(), getActivity());
mAdapter.addFragment("Business");
mAdapter.addFragment("Product");
mPager.setAdapter(mAdapter);
mPager.setOffscreenPageLimit(2);
mPagerSlidingTabStrip.setViewPager(mPager);
return rootView;
}
那怎么解决呢?对不起我的英文
答案 0 :(得分:0)
我的问题是:
mAdapter = new FragmentSearchResultAdapter(getActivity().getSupportFragmentManager(), getActivity());
我改变:
mAdapter = new FragmentSearchResultAdapter(getChildFragmentManager(), getActivity());