0

I have a LinearLayout as a container in which I added views programatically. I tried to set elevation to the container. It's not working.Please refer to the layout below.

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="5dp"
        android:clipToPadding="false">

      <LinearLayout
            android:id="@+id/container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:background="#00FFFFFF"
            android:orientation="vertical"
            android:elevation="@dimen/cardview_default_elevation">

      </LinearLayout>

     //Other layouts ...

</LinearLayout>

I've also tried to set the elevation to the view to be added without setting elevation to container from xml.

View view = // get some view here 
view.setPadding(0, 0, 0, Utils.dpToPx(10));
view.setElevation(2.0f);
container.addView(view);

It's also not working. Can someone help me out ?? Thanks!!

Moe Han
  • 38
  • 6
  • 1
    Possible duplicate of [Android "elevation" not showing a shadow](https://stackoverflow.com/questions/27477371/android-elevation-not-showing-a-shadow) – MadScientist Oct 31 '17 at 08:24

1 Answers1

0

Be sure that you are using minSdk 21 or higher

Constantin N.
  • 2,739
  • 2
  • 16
  • 27