使用RelativeLayout时,工具栏出现在布局顶部

时间:2016-05-14 05:36:41

标签: android android-layout android-toolbar

我有一个顶部和底部工具栏以及它们之间的ImageView:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mainRelativeLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white" >

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar_top"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:background="?attr/colorPrimary"
        android:minHeight="?attr/actionBarSize" />

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar_bottom"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:background="?attr/colorPrimary"
        android:layout_alignParentBottom="true"
        android:minHeight="?attr/actionBarSize" />

    <omar.myapp.app.viewpager.ImageViewPager
        android:layout_below="@id/toolbar_top"
        android:layout_above="@id/toolbar_bottom"
        android:id="@+id/mainViewPager"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        />

</RelativeLayout>

问题是底部工具栏出现在ViewPager的顶部:

enter image description here

图像正确位于顶部工具栏下方,但显示在底部工具栏后面。

有谁知道为什么图像会在底部工具栏后面而不是停留在它上面?

1 个答案:

答案 0 :(得分:1)

隐藏视图仅在相对框架布局中完成。

使用线性布局解决您的问题......

查看您的编辑xml ...

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mainRelativeLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white"
    android:orientation="vertical">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar_top"
        android:layout_height="50dp"
        android:layout_width="match_parent"
        android:background="?attr/colorPrimary"
        android:minHeight="?attr/actionBarSize" />

    <omar.myapp.app.viewpager.ImageViewPager
        android:id="@+id/mainViewPager"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:src="@drawable/splash"
        android:scaleType="fitXY"
        android:layout_weight="1"
        />

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar_bottom"
        android:layout_height="50dp"
        android:layout_width="match_parent"
        android:background="?attr/colorPrimary"
        android:minHeight="?attr/actionBarSize" />

</LinearLayout>

此代码的输出: - enter image description here

享受编码............