设置layout_weight =“1”后未显示ViewPager

时间:2013-07-25 11:05:21

标签: android android-layout android-viewpager

我的布局如下

<LinearLayout
        android:id="@+id/home_screen"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
        <android.support.v4.view.ViewPager
            android:id="@+id/slide_pager"
            android:layout_width="wrap_content"
            android:layout_weight="1"
            android:layout_height="0dp" >
        </android.support.v4.view.ViewPager>

        <RelativeLayout
            android:id="@+id/footer"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:visibility="visible" >
            < .. views />
        </RelativeLayout>  </LinearLayout>

当我将RelativeLayout页脚的高度设置为200dp时,我会看到ViewPager。如果页脚是'wrap_content',则ViePager完全消失。我尝试将ViewPager的重量设置为1,但没有用。我希望页脚为wrap_content。和ViewPager占用剩余的空间。

谢谢你。

即使将layout_height设置为wrap_content,问题仍然存在。

2 个答案:

答案 0 :(得分:0)

如果在垂直LinearLayout中,将宽度设置为0dp,则不会显示。也发生在水平的LinearLayout和0dp的高度。

只需将宽度更改为wrap_content(或其他任何内容)。

答案 1 :(得分:0)

问题是我们必须根据需要为子布局提供权重。所以我将viewpager的权重设置为.75并将剩余布局设置为.25,现在视图寻呼机将显示到屏幕的3/4。

<LinearLayout
        android:id="@+id/home_screen"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
        <android.support.v4.view.ViewPager
            android:id="@+id/slide_pager"
            android:layout_width="match_parent"
            android:layout_weight=".75"
            android:layout_height="0dp" >
        </android.support.v4.view.ViewPager>

        <RelativeLayout
            android:id="@+id/footer"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:layout_weight=".25"
            android:visibility="visible" >
            < .. views />
        </RelativeLayout>  </LinearLayout>