Android viewpager weight - 全屏主题

时间:2013-04-19 12:13:38

标签: android android-viewpager

我需要viewpager的帮助。

我有两个线性布局,他们将我的主视图分成2行。我想将viewpager添加到第一行,但是当主题是全屏时它会覆盖整个页面。

等待你的帮助。谢谢     

<LinearLayout
    android:id="@+id/top"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="10"
    android:orientation="vertical" >
    <widgets.Header
        android:id="@+id/headerWidget"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="2" >
    </widgets.Header>

    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="8" >
    </android.support.v4.view.ViewPager>
</LinearLayout>
<LinearLayout
    android:id="@+id/bottom"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="10"
    android:orientation="vertical" />

1 个答案:

答案 0 :(得分:2)

更改xml代码如下

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".HomePage" >
    <Widgets.Header
        android:id="@+id/headerWidget"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.2" >
    </Widgets.Header>
    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_weight="0.8" >
    </android.support.v4.view.ViewPager>
    <LinearLayout
        android:id="@+id/bottom"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="vertical" >
    </LinearLayout>
</LinearLayout>

注意:

我不知道为什么在使用FullScreen Theme的layout_height中将0dp设置为ViewPager无法正确呈现layout_weight。将layout_height的{​​{1}}设置为某个ViewPager(比如说​​1dp)而不是dpmatch_parent效果很好。