所以我制作了一个包含带有TabPageIndicator的Viewpager的Fragment Activity来从一个片段滑动到另一个片段,在每个片段中我创建了一个包含ViewPager作为Header视图的ListView,问题是viewPager不刷卡即使我取消了main viewPager swipping
我在ActionBar标签上尝试了同样的事情,但它无法正常工作
这是我的片段活动
public class SampleTabsStyled extends FragmentActivity {
private static final String[] CONTENT = new String[] { "Recent", "Artists",
"Albums", "Songs", "Playlists", "Genres" };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.simple_tabs);
FragmentPagerAdapter adapter = new GoogleMusicAdapter(
getSupportFragmentManager());
final ViewPager pager = (ViewPager) findViewById(R.id.pager);
pager.setAdapter(adapter);
pager.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
switch (event.getAction()) {
case MotionEvent.ACTION_MOVE:
pager.requestDisallowInterceptTouchEvent(true);
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
pager.requestDisallowInterceptTouchEvent(false);
break;
}
return true;
}
});
TabPageIndicator indicator = (TabPageIndicator) findViewById(R.id.indicator);
indicator.setViewPager(pager);
}
class GoogleMusicAdapter extends FragmentPagerAdapter {
public GoogleMusicAdapter(FragmentManager fm) {
super(fm);
}
@Override
public ListFragment getItem(int position) {
// return TestFragment.newInstance(CONTENT[position %
// CONTENT.length]);
return new SecondTestFragment();
}
@Override
public CharSequence getPageTitle(int position) {
return CONTENT[position % CONTENT.length].toUpperCase();
}
@Override
public int getCount() {
return CONTENT.length;
}
}
}
这是我的ListFragment
public class SecondTestFragment extends ListFragment {
String[] countries = new String[] { "India", "Pakistan", "Sri Lanka",
"China", "Bangladesh", "Nepal", "Afghanistan", "North Korea",
"South Korea", "Japan" };
View mheaderView;
ViewPager pager;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
/** Creating an array adapter to store the list of countries **/
View parent = inflater.inflate(R.layout.fragment_list, null);
// mheaderView = inflater.inflate(R.layout.item_list, null);
mheaderView = inflater.inflate(R.layout.featured_pager, null);
pager = (ViewPager) mheaderView.findViewById(R.id.featuredPaper);
pagerAdapter pa = new pagerAdapter(getActivity());
pager.setAdapter(pa);
pager.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
Log.d("Motion Event", event.toString());
return false;
}
});
CirclePageIndicator indicator = (CirclePageIndicator) mheaderView.findViewById(R.id.featured_indicator);
indicator.setViewPager(pager);
return parent;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onActivityCreated(savedInstanceState);
if (mheaderView != null) {
this.getListView().addHeaderView(mheaderView);
Log.d("pager", "not null");
} else {
Log.d("pager", "null");
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),
android.R.layout.simple_list_item_1, countries);
setListAdapter(adapter);
getListView().setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
getListView().getParent().requestDisallowInterceptTouchEvent(true);
return false;
}
});
((PullToRefreshListView) getListView()).setOnRefreshListener(new OnRefreshListener() {
@Override
public void onRefresh() {
// Do work to refresh the list here.
}
});
}
}
答案 0 :(得分:7)
在父视图寻呼机中覆盖 canScroll 方法。
@Override
protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) {
if(v != this && v instanceof ViewPager) {
return true;
}
return super.canScroll(v, checkV, dx, x, y);
}
检查此答案