Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android elevation property not working

Since upgrading to SDK 21 I've been trying to use the elevation property but it never seems to work.

I want to elevate a frame above others so I'm setting the following

android:elevation="4dp"

but there's no sign of shadow. I've tried buttons and framelayouts but not got any elevation

So here's the full tag

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:id="@+id/panel_card"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#ffffff"
    android:elevation="4dp"
    >

Am I missing something else I need to add

like image 637
Andrew Avatar asked Nov 08 '14 01:11

Andrew


People also ask

How do I set elevation in Android?

To set the default (resting) elevation of a view, use the android:elevation attribute in the XML layout. To set the elevation of a view in the code of an activity, use the View. setElevation() method. To set the translation of a view, use the View.

What is Android TranslationZ?

TranslationZ is a dynamic property used for animation. Basically it's needed to nicely handle elevation changes.

How do I change the elevation color in react native?

In addition, box shadows in React Native are also not supported on Android, based on this. Save this answer. Show activity on this post. As per @rclai Answer, You cannot change the Elevation color in Android.


2 Answers

Make sure that the background for the container holding the FrameLayout is not transparent.

like image 170
William Avatar answered Sep 22 '22 09:09

William


According to this Z = Elevation + TranslationZ

so try this:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:card_view="http://schemas.android.com/apk/res-auto"
  android:id="@+id/panel_card"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:background="#ffffff"
  android:elevation="4dp"
  android:translationZ="4dp">
like image 31
Tinashe Avatar answered Sep 18 '22 09:09

Tinashe