本文介绍了如何获得多个ViewPagers成滚动型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现一个布局,其中包含ViewPagers列表。每个ViewPager是swipeable独立。请参见链接下面的图片。

I am trying to implement a layout, which contains a list of ViewPagers. Each ViewPager is swipeable independently. See the link to the picture below.

布局的图片

我试着用滚动型和它里面ViewPagers一个LinearLayout中,但我只得到示出了一个ViewPager。它甚至有可能获得一些ViewPagers在一个屏幕上?

I tried with ScrollView and a LinearLayout with ViewPagers inside it, but I only get one ViewPager shown. Is it even possible to get several ViewPagers on one screen?

我的code到目前为止:的main.xml

my code so far:main.xml

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <android.support.v4.view.ViewPager
            android:id="@+id/viewpager2"
            android:layout_width="wrap_content"
            android:layout_height="100dp" />

        <android.support.v4.view.ViewPager
            android:id="@+id/viewpager3"
            android:layout_width="wrap_content"
            android:layout_height="100dp" />
    </LinearLayout>

</ScrollView>

MainActivity

public class MainActivity extends Activity{
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        ViewPagerAdapter adapter2 = new ViewPagerAdapter( this );
        ViewPager pager = (ViewPager)findViewById( R.id.viewpager2 );
        pager.setAdapter( adapter2 );

        ViewPagerAdapter adapter3 = new ViewPagerAdapter( this );
        ViewPager pager3 =
            (ViewPager)findViewById( R.id.viewpager3 );
        pager3.setAdapter( adapter3 );
    }

}

任何想法?谢谢! 编辑:这code的实际工作

Any ideas?Thanks! this code actually works!

推荐答案

在你的LinearLayout,在你的XML。设置安卓weightSum =2。对于每个viewpager,设置的android:layout_weight =1。此外,设置的LinearLayout的每个孩子的高度0dp。这应该做的伎俩

On your LinearLayout, in your XML. Set android:weightSum="2". For each viewpager, set android:layout_weight="1". Also, set the height of each child of the LinearLayout to 0dp. That should do the trick

这篇关于如何获得多个ViewPagers成滚动型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-13 20:23