简体   繁体   中英

view below and overlays another view in android

i want to make a view that will be below another view and overlays it too

i made the following

  <RelativeLayout  android:layout_height="wrap_content" android:layout_width="wrap_content">


        <include layout="@layout/toolbar" android:id="@+id/tool"
            />


        <include layout="@layout/content_main"
            android:layout_width="match_parent"
                 android:layout_height="match_parent"
            android:layout_below="@+id/tool"
            android:layout_marginBottom="30dp"
         />



        </RelativeLayout>

but it didn't work, any solutions?

First, you'll need to reverse the order of the views, toolbar should hide content_main so it should be added after it.

Second, you can use negative margins for this, you tell content_main to be below toolbar , and then put a negative top margin on it, so it moves a bit higher, and beneath toolbar .

Example:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ff0000" >
    <TextView
        android:text="first line, will be partially covered. fdjkfsjdf kldsjfkdsljfklds "
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/toolbar"
        android:layout_marginTop="-20dp"
        android:textSize="36sp"
        android:fontFamily="sans-serif-light"
        android:background="#00ff00"/>
    <TextView
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:background="#0000ff"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:textSize="36sp"
        android:text="TOOLBAR" />
</RelativeLayout>

And result:

结果截图

尝试使用FrameLayout,而不是RelativeLayout。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM