简体   繁体   中英

How to set elevation to ViewGroup or Layouts

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!!

确保您使用的是minSdk 21或更高版本

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM