简体   繁体   中英

How to overlay view in RelativeLayout?

Here is what I have:

Is it possible to somehow lower the button overlay layer, but without change layout. I am using Relative. The problem is that when the button goes to the line location of digits small part of button not visible.

Here fragment of .xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:materialdesign="http://schemas.android.com/apk/res-auto"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="65dp"
android:orientation="vertical"
android:padding="8dp"
android:background="@drawable/shadow_listitem">

<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
          android:textAppearance="?android:attr/textAppearanceLarge" android:text="Task is Finish!"
          android:id="@+id/txtFinish"
          android:visibility="gone"

          android:layout_alignBottom="@+id/tvDays"
          android:layout_alignParentLeft="true"
          android:layout_alignParentStart="true"/>
<TextView android:layout_width="wrap_content"
          android:layout_height="wrap_content"

          android:textAppearance="?android:attr/textAppearanceLarge" android:text="Name" android:id="@+id/tvName"
          android:layout_alignParentTop="true"
          android:layout_alignParentRight="true"
          android:layout_alignParentEnd="true"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
          android:textAppearance="?android:attr/textAppearanceSmall"
          android:layout_marginLeft="-27dp"
          android:text="0000" android:id="@+id/tvDays"
          android:layout_alignTop="@+id/textView4"
          android:layout_toLeftOf="@+id/textView4"
          android:layout_toStartOf="@+id/textView4"/>

<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
          android:textAppearance="?android:attr/textAppearanceSmall" android:text="00" android:id="@+id/tvHours"
          android:layout_toLeftOf="@+id/textView2"
          android:layout_toStartOf="@+id/textView2"
          android:layout_below="@+id/tvName"/>

<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
          android:textAppearance="?android:attr/textAppearanceSmall" android:text="00" android:id="@+id/tvMinutes"

          android:layout_alignTop="@+id/textView8"
          android:layout_toLeftOf="@+id/textView8"
          android:layout_toStartOf="@+id/textView8"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
          android:textAppearance="?android:attr/textAppearanceSmall" android:text=":" android:id="@+id/textView8"
          android:layout_alignTop="@+id/tvSeconds"
          android:layout_toLeftOf="@+id/tvSeconds"
          android:layout_toStartOf="@+id/tvSeconds"/>
<TextView android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textAppearance="?android:attr/textAppearanceSmall" android:text="00" android:id="@+id/tvSeconds"

          android:layout_below="@+id/tvName"
          android:layout_alignRight="@+id/tvName"
          android:layout_alignEnd="@+id/tvName"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
          android:textAppearance="?android:attr/textAppearanceMedium" android:text="Limit: "
          android:visibility="gone" android:id="@+id/txtLimit"
          android:layout_alignBottom="@+id/tvDays"
          android:layout_toLeftOf="@+id/tvDays"
          android:layout_toStartOf="@+id/tvDays"
          android:layout_marginRight="133dp"

          android:layout_marginEnd="93dp"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
          android:textAppearance="?android:attr/textAppearanceSmall" android:text="00" android:id="@+id/limDay"
          android:visibility="gone"
          android:layout_marginLeft="50dp"
    android:layout_alignBottom="@+id/txtLimit"
          android:layout_marginStart="50dp"
          android:layout_alignTop="@+id/tvDays"

          android:layout_alignLeft="@+id/txtLimit"
          android:layout_alignStart="@+id/txtLimit"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
          android:textAppearance="?android:attr/textAppearanceSmall" android:text="00" android:id="@+id/limHours"
          android:visibility="gone"
    android:layout_alignBottom="@+id/txtLimit"

          android:layout_alignTop="@+id/limDay"
          android:layout_toRightOf="@+id/limDay"
          android:layout_toEndOf="@+id/limDay"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
          android:textAppearance="?android:attr/textAppearanceSmall" android:text="00" android:id="@+id/limMin"
          android:visibility="gone"
          android:layout_alignTop="@+id/limHours"
    android:layout_toRightOf="@+id/limHours"

    android:layout_alignBottom="@+id/txtLimit"
          />
<com.software.shell.fab.ActionButton
    android:id="@+id/btStart"
    style="@style/fab_action_button_style"
    fab:type="mini"
    fab:image="@drawable/fab_plus_icon"
    fab:rippleEffect_enabled="true"
    fab:button_color="@color/primaryColor"
    android:focusable="false"
    fab:shadowResponsiveEffect_enabled="true"
    fab:button_colorRipple="@color/primaryColorDark"
    fab:button_colorPressed="@color/fab_material_blue_500"
    android:layout_alignParentTop="true"
    android:layout_marginTop="-14dp"
    fab:shadow_yOffset="0.0dp"
    android:layout_alignParentStart="true" />

To overlay your parent layout should be a FrameLayout. For example:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/map_place_box"
    android:layout_width="200dp"
    android:layout_height="wrap_content"
    android:background="@color/primary"
    android:padding="10dp">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher"/>

    <TextView
        android:id="@+id/place"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Casa da mae joana"
        android:textColor="@android:color/white"
        android:textSize="25dp"
        />
</FrameLayout>

The text view is overlaying the image.

I hope it helps.

You can keep the FrameLayout at top of the hierarchy.Then keep RelativeLayout and ActionButton in this FrameLayout.
Your View hierarchy should be like this:

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/map_place_box"
    android:layout_width="200dp"
    android:layout_height="wrap_content"
    android:background="@color/primary"
    android:padding="10dp">

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
    // Keep all of your textviews inside this Relative Layout.
    </RelativeLayout>  
    <com.software.shell.fab.ActionButton
        android:id="@+id/btStart"
        style="@style/fab_action_button_style"
        fab:type="mini"
        fab:image="@drawable/fab_plus_icon"
        fab:rippleEffect_enabled="true"
        fab:button_color="@color/primaryColor"
        android:focusable="false"
        fab:shadowResponsiveEffect_enabled="true"
        fab:button_colorRipple="@color/primaryColorDark"
        fab:button_colorPressed="@color/fab_material_blue_500"
        android:layout_alignParentTop="true"
        android:layout_marginTop="-14dp"
        fab:shadow_yOffset="0.0dp"
        android:layout_alignParentStart="true" />
</FrameLayout>

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