这可能是显而易见的,并且是一个完全不必要的帖子,但是我一直在解决一个方法来允许在VewPager中的页面上进行垂直滚动功能,而且谷歌甚至这里甚至没有什么决议.我发现一些人声称要解决这个问题,但似乎有所扩大和复杂.所以对于那些可能在寻找同样的问题的人来说,解决方案.有了这个(你会想要比我在这里写的更大的字符串),你将能够垂直滚动内容并在页面之间滑动.
layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.v4.view.ViewPager android:id="@+id/conpageslider" android:layout_width="match_parent" android:layout_height="match_parent"/> </LinearLayout>
滚动查看器类
public class ScrollingViewPager extends Activity{ private ViewPager pager; private Context cxt; private CharSequence[] pages = {"stuff","more stuff","other stuff"}; private PageSlider ps; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setContentView(R.layout.layout); cxt = this; ps = new PageSlider(); pager = (ViewPager) findViewById(R.id.conpageslider); pager.setAdapter(ps); } public class PageSlider extends PagerAdapter{ @Override public int getCount() { return pages.length; } @Override public Object instantiateItem(View collection,int position) { ScrollView sc = new ScrollView(cxt); sc.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT)); sc.setFillViewport(true); TextView tv = new TextView(cxt); tv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT)); tv.setText(pages[position]); tv.setPadding(5,5,5); sc.addView(tv); ((ViewPager) collection).addView(sc); return sc; } @Override public void destroyItem(View collection,int position,Object view) { ((ViewPager) collection).removeView((ScrollView) view); } @Override public boolean isViewFromObject(View view,Object object) { return view==((ScrollView)object); } } }