gpt4 book ai didi

android - 带有 Viewpager 的 ListView 作为 TabPageIndicator 内的标题

转载 作者:太空宇宙 更新时间:2023-11-03 12:19:17 25 4
gpt4 key购买 nike

所以我制作了一个 fragment Activity ,其中包含带有 TabPageIndicator 的 Viewpager 以从 fragment 滑动到另一个 fragment ,并且在每个 fragment 中我制作了一个包含 ViewPager 作为标题 View 的 ListView 问题是即使我取消了 viewPager 也不会滑动主 viewPager 滑动

我在 ActionBar 选项卡上尝试了同样的事情,但它也没有用

enter image description here

这是我的 fragment Activity

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.

}
});


}

最佳答案

重写父 View 分页器中的 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);
}

检查这个答案

ViewPager inside ViewPager

关于android - 带有 Viewpager 的 ListView 作为 TabPageIndicator 内的标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21363179/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com