Android View height in CardView not showing

I have a RelativeLayout inside a CardView that I want to raise in Android Lollipop, but the height is not displayed (no shadow is displayed):

enter image description here

My layout file:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:android.support.v7.cardview="http://schemas.android.com/apk/res-auto"
    style="@style/CardViewStyle"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:elevation="5dp"
    android:orientation="horizontal"
    android.support.v7.cardview:cardElevation="5dp">

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/list_selector"
    android:paddingBottom="5dp">

    <ImageView
        android:id="@+id/article_thumb"
        android:layout_width="match_parent"
        android:layout_height="150dp"
        android:layout_alignParentTop="true"
        android:contentDescription="@string/app_name"
        android:scaleType="centerCrop" />

    <TextView
        android:id="@+id/article_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/article_thumb"
        android:layout_marginEnd="10dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginStart="10dp"
        android:ellipsize="middle"
        android:linksClickable="false"
        android:longClickable="false"
        android:text="@string/title"
        android:textAppearance="@style/TextAppearance.AppCompat.Title"
        android:textColor="@color/black" />

    <TextView
        android:id="@+id/article_date"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/article_title"
        android:layout_alignStart="@+id/article_title"
        android:layout_below="@+id/article_title"
        android:layout_marginTop="10dp"
        android:text="@string/date"
        android:textAppearance="@style/TextAppearance.AppCompat.Light.Widget.PopupMenu.Small"
        android:textColor="@color/gray" />

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignEnd="@+id/article_title"
        android:layout_alignRight="@+id/article_title"
        android:layout_below="@+id/article_title"
        android:layout_marginTop="10dp"
        android:elevation="30dp"
        android:translationZ="30dp">

        <ImageView
            android:id="@+id/redbubble"
            android:layout_width="25dp"
            android:layout_height="25dp"
            android:layout_gravity="center"
            android:contentDescription="@string/app_name"
            android:scaleType="centerCrop"
            android:src="@drawable/redbubble" />

        <TextView
            android:id="@+id/article_comment_bubble"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:textAppearance="@style/TextAppearance.AppCompat.Small"
            android:textColor="@color/white" />
    </RelativeLayout>

</RelativeLayout>

      

So, inside this layout, I added these two lines to the RelativeLayout to make the height:

android:elevation="30dp"
android:translationZ="30dp"

      

Any idea why it isn't shown? At the moment I am testing it with an emulator using Android API 21 (Lollipop).

+3


source to share


5 answers


In root layout in xml you need

xmlns:card_view="http://schemas.android.com/apk/res-auto"

      



below is the code for the card

card_view:cardElevation="5dp"

      

+7


source


The shadow is not displayed because it is drawn outside its RelativeLayout and the view is encrypted to its border.



Add android:clipChildren="false"

to your parent RelativeLayout or add a small amount of padding to your view and setandroid:clipToPadding="false"

+4


source


You have to add android: elevation property in redbubble view image. To view the Shadow of an element, you must add android: elevation to this view .

I would suggest you change your redbubble image to the following:

    <ImageView
        android:id="@+id/redbubble"
        android:layout_width="25dp"
        android:layout_height="25dp"
        android:layout_gravity="center"
        android:contentDescription="@string/app_name"
        android:scaleType="centerCrop"
        android:elevation="2dp"
        android:src="@drawable/redbubble" />

      

+1


source


I noticed the same problem and the elevation is not shown because the line:

Android: layout_below = "@ + id / ...."

Typically, this is because the shadow is drawn outside of the visible boundaries.

+1


source


delete

android:hardwareAccelerated="false" from manifest

      

0


source







All Articles