Reputation: 81
I'm building my custom layout for my Android application and I'm trying adding elevation to one LinearLayout but it doesn't work, I tried a lot of solutions found on web but nothing with success.
My xml is this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp">
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@drawable/admin_gray"
app:civ_border_width="2dp"
app:civ_border_color="@android:color/darker_gray"
android:layout_marginRight="10dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/tvNewsAggiuntoCommentoDescrizione"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Username ha commentato una ricetta:"/>
<TextView
android:id="@+id/tvNewsAggiuntoCommentoData"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="25/05/1989 12:58:07"
android:textColor="@android:color/darker_gray" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@color/white"
android:elevation="10dp">
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/rounded_linear_layout_tile_ricetta"
android:layout_marginBottom="5dp"
>
<ImageView
android:id="@+id/imageViewRicetta"
android:layout_width="match_parent"
android:layout_height="150dp"
android:src="@mipmap/cibo"
android:scaleType="centerCrop"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Antipasto"
android:background="@color/colorCategoriaRicetta"
android:layout_alignBaseline="@id/imageViewRicetta"
android:layout_gravity="right|top"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@android:color/white"
android:padding="3dp"
android:id="@+id/tvCategoriaRicetta"
android:elevation="4dp"/>
<TextView
android:id="@+id/tvTitoloRicetta"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Maxi hamburger con maionese"
android:background="@color/colorBackgroundTextViewNomeRicetta"
android:layout_alignBaseline="@id/imageViewRicetta"
android:layout_gravity="left|bottom"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/white"
android:paddingLeft="5dp"
android:textStyle="bold" />
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/imageViewFotoAltroUtente"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:src="@drawable/admin_gray"
app:civ_border_width="2dp"
app:civ_border_color="@android:color/darker_gray" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp">
<TextView
android:id="@+id/tvUsernameUtenteCommento"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="Username"/>
<TextView
android:id="@+id/tvNewsAggiuntoCommentoCommento"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Questo è il testo di esempio di un commento a una ricetta"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Attention, the layout with elevation is not the top LinearLayout, it's the layout with "elevation" attribute...
Can you help me to find a solution in order to obtain the elevation correctly?
Thanks a lot.
Upvotes: 1
Views: 2990
Reputation: 2919
Add this propriety to you LinearLayout
:
android:outlineProvider="bounds"
Make sure all view parents from the element you wanna to set elevation has no padding. This can cause the shadow to be clipped. A solution for that is add this property to all parent view:
android:clipToPadding="false"
Also, shadows will not show if you have this line in the manifest:
android:hardwareAccelerated="false"
Upvotes: 1