How to use Elevation? [duplicate]

0

I used elevation to test, but I inserted it into the XML of a button and it did not change elevation of it, if you can help me, thank you right away

    
asked by anonymous 22.03.2017 / 04:35

1 answer

0

The elevation attribute will only have some effect if you are using API level 21 or higher. See some tips on Elevation & shadows .

According to the Material Design specifications , each component has its ideal elevation limit, such as Button , which defaults to% with%.

In your case, what may be happening is that the default properties of the button are overwriting yours. If you set this elevation from 8dp , for example to 10dp , it will certainly work.

See an example:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="20dp"
        android:background="#f0f0f0"
        android:elevation="16sp"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true">

        <LinearLayout
            android:layout_width="80dp"
            android:layout_height="80dp"
            android:background="#ffffff"
            android:layout_margin="20dp"
            android:elevation="2dp"/>
    </LinearLayout>
</RelativeLayout>

Image

Note:Istronglyadviseyoutofollowthe Material Design recommendations for elevations and shadings, so you can continue with the same elegance.

    
22.03.2017 / 16:19