Java Android中带有Viewpager的静态内容

Java Android中带有Viewpager的静态内容,java,android,xml,android-studio,Java,Android,Xml,Android Studio,我尝试了多种方法在activity_main.xml中添加页脚和页眉,其中包含一个viewpager。到目前为止,当我在viewpager上方添加页眉时,它会显示在最终结果中,但页脚不会。 下面是xml代码 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_wid

我尝试了多种方法在activity_main.xml中添加页脚和页眉,其中包含一个viewpager。到目前为止,当我在viewpager上方添加页眉时,它会显示在最终结果中,但页脚不会。 下面是xml代码

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg50"
android:orientation="vertical">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:background="#FF0000"
    android:orientation="vertical">

</LinearLayout>

<android.support.design.widget.TabLayout
    android:id="@+id/tabs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="?attr/actionBarSize"
    app:tabGravity="fill"
    app:tabMode="fixed"
    app:tabSelectedTextColor="@color/colorAccent"
    app:tabTextColor="#FFF" />

<android.support.v4.view.ViewPager
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />


<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:background="#FF0000"
    android:orientation="vertical">

</LinearLayout>


因此,问题是,如何在查看页面下方显示内容。

更改您的查看页面布局高度以包装内容

或者只需将根布局更改为
,并设置“将此标记添加到视图页面”

像这样:

<RelativeLayout>
    ...
    <ViewPager
      ...
      android:layout_height="match_parent"
      android:layout_above="@id/your_footer_id"/>
    ...
</RelativeLayout>

...
...

设置您的查看页面:

android:layout_height="0dp"
android:layout_weight="1"

这将使它在布局其他子项后填充LinearLayout中的所有可用空间。

如果您希望在下面的
ViewPager
中使用静态页脚,可以使用下面的布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:orientation="vertical">

<LinearLayout
    android:id="@+id/header"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:background="#FF0000"
    android:orientation="vertical">

</LinearLayout>

<android.support.design.widget.TabLayout
    android:id="@+id/tabs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/header"
    android:background=""
    android:minHeight="?attr/actionBarSize"
    app:tabGravity="fill"
    app:tabMode="fixed"
    app:tabSelectedTextColor="@color/colorAccent"
    app:tabTextColor="#FFF" />

<android.support.v4.view.ViewPager
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/footer"
    android:layout_below="@+id/tabs" />

<LinearLayout
    android:id="@+id/footer"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_alignParentBottom="true"
    android:background="#FF0000"
    android:orientation="vertical"></LinearLayout>

</RelativeLayout>


至少对我来说,你的问题还不清楚。你能编辑它吗?问题到底是什么?viewpager下面的任何内容都不显示Rap_内容不起作用。但是如果我设置一个固定的高度,比如300dp,它就可以工作。如何使其与wrap_内容一起工作?简单而直接!
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:orientation="vertical">

<LinearLayout
    android:id="@+id/header"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:background="#FF0000"
    android:orientation="vertical">

</LinearLayout>

<android.support.design.widget.TabLayout
    android:id="@+id/tabs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/header"
    android:background=""
    android:minHeight="?attr/actionBarSize"
    app:tabGravity="fill"
    app:tabMode="fixed"
    app:tabSelectedTextColor="@color/colorAccent"
    app:tabTextColor="#FFF" />

<android.support.v4.view.ViewPager
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/footer"
    android:layout_below="@+id/tabs" />

<LinearLayout
    android:id="@+id/footer"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_alignParentBottom="true"
    android:background="#FF0000"
    android:orientation="vertical"></LinearLayout>

</RelativeLayout>