'How to set elevation of parent view taking into consideration all its children?
I have RelativeLayout
parent, which has 2 children horizontally positioned next to each other. First children is LinearLayout
has custom background shape and some content in it and second one is ImageView
which is representing custom shaped end of background. As they are next to each other, they are forming one single uninterrupted background.
Problem is that if I set android:elevation="8dp"
to RelativeLayout
parent, Its not visible at all. I tried clipToPadding
false, but nothing has changed.
LinearLayout has dynamic height (wrap_content
) and ImageView
is stretching based on first layout height(android:layout_alignTop, android:layout_alignBottom
)
Here is quick sketch of that layout (I cant share actual screenshot - im under NDA).
Mockup layout:
<?xml version="1.0" encoding="utf-8"?>
<layout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable name="CustomRes" type="com.project.utils.CustomResources"/>
</data>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/transparent"
android:elevation="@dimen/padding_small"
android:layout_margin="@dimen/padding_small">
<LinearLayout
android:id="@+id/mainContentLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toStartOf="@id/endElement"
android:orientation="horizontal"
android:background="@drawable/bg_round_left"
android:backgroundTint="@color/blue">
<RelativeLayout
android:id="@+id/infoParent"
android:padding="@dimen/padding_medium"
android:paddingEnd="0dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/infoMain"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:ignore="UselessParent">
<LinearLayout
android:id="@+id/baseInfoLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toStartOf="@id/infoTime"
android:orientation="vertical">
<TextView
android:id="@+id/city"
style="@style/item_text_secondary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="--"
android:textColor="@color/white" />
<TextView
android:id="@+id/station"
style="@style/item_text_primary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="--" />
<TextView
android:id="@+id/duration"
style="@style/item_text_primary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="--" />
</LinearLayout>
<TextView
android:id="@+id/infoTime"
style="@style/item_activated_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:text="--" />
<RelativeLayout
android:id="@+id/itemTimeLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/padding_medium"
android:layout_below="@id/baseInfoLayout"
tools:ignore="UselessParent">
<TextView
android:id="@+id/timeLabel"
style="@style/item_activated_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:text="Activated at: " />
<TextView
android:id="@+id/activatedAt"
style="@style/item_activated_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/timeLabel"
android:layout_alignParentEnd="true"
android:text="--"
android:textStyle="bold" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
<ImageView
android:id="@+id/endElement"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignTop="@id/mainContentLayout"
android:layout_alignBottom="@id/mainContentLayout"
android:backgroundTint="@color/blue"
android:background="@drawable/item_ending_element" />
</RelativeLayout>
</layout>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|