我在片段中有一个viewpager,我可以在页面中滚动。当我向后台堆栈添加一个新片段时,新片段在旧片段容器中按预期显示。一旦我按回旧片段,但是视图寻呼机不再工作,而是焦点切换到滑动菜单(我提交的片段布局是feinsteins菜单中的中央布局),当我滑动滑动菜单时打开而不是移动到viewpager中的下一页。为什么会这样?
这是我的Viewpager适配器,它在片段atm
中被子类化 static class SamplePagerAdapter extends PagerAdapter {
private static int[] sDrawables = { R.drawable.main1, R.drawable.main3,
R.drawable.main2, R.drawable.main3, R.drawable.main4,
R.drawable.main5 };
@Override
public int getCount() {
return sDrawables.length;
}
@Override
public View instantiateItem(ViewGroup container, int position) {
ImageView imageView = new ImageView(container.getContext());
imageView.setImageResource(sDrawables[position]);
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//thiscalls back to the Fragmentctivity and switches to the new fragment, problems arise when I go back to this fragment and the viewpager wont swipe to next page
((LeftAndRightActivity) cx).switchFragmentTo(12);
}
});
// Now just add ImageView to ViewPager and return it
container.addView(imageView, LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT);
return imageView;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
}
这是我的片段的onCreateView(),其中包含viewpager(我实际上正在使用ChrisBanes的PullToRefresh Viewpager)
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
if (container == null)
return null;
if (v != null)
return v;
v = inflater.inflate(R.layout.savescreenlayout, container, false);
mPullToRefreshViewPager = (PullToRefreshBase) v
.findViewById(R.id.pull_refresh_viewpager);
mPullToRefreshViewPager.setOnRefreshListener(this);
mPullToRefreshViewPager.setMode(Mode.PULL_FROM_END);
vp = (ViewPager) mPullToRefreshViewPager.getRefreshableView();
vp.setAdapter(new SamplePagerAdapter());
return v;
}
我的第一次使用viewpager的Fragment被提交时很好,就在我从任何其他片段返回时,viewpager停止分页并且滑动菜单打开了。感谢您提前提供任何帮助