Summary of Methods for Shadow Effect of Pictures Built on Android Live Broadcasting System Platform

  • 2021-12-19 06:37:18
  • OfStack

Android live broadcast system platform construction, pictures to achieve shadow effect of several methods, the following three methods are listed for everyone, the specific code is as follows:

The first one uses layer-list


<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

<!-- The left of the bottom layer is far from the left of the upper layer 3dp,  The top of the bottom layer, away from the top of the upper layer 6dp, If this control is not done, the left and upper sides of the bottom and upper layers will overlap in 1 Rise -->
<item android:left="3dp"
android:top="6dp">
<shape>
<solid android:color="#b4b5b6"/>
</shape>
</item>

<!-- The right of the upper layer is far from the right of the bottom layer 3dp,  The bottom of the upper layer is away from the bottom of the bottom layer 6dp-->
<item android:bottom="6dp"
android:right="3dp">
<shape>
<solid android:color="#fff"/>
</shape>
</item>

</layer-list>

The second uses the shadow attribute

shadowDX, shadowDy and shadowRadius refer to the transverse and ordinate offsets of shadows and the radius of shadows respectively.
If it is TextView, it can be set directly in the layout:


<TextView
android:id="@+id/test_shadow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="60sp"
android:textColor="#cc000000"
android:text="Test Shadow"
android:layout_gravity="center"
android:shadowColor="#aa22ff22"
android:shadowRadius="10"
android:shadowDx="0"
android:shadowDy="0"
/>

The third uses android: elevation attribute


<TextView
android:id="@+id/btn_test_performance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:elevation="5dp"
android:text="@string/hello"
android:background="@drawable/shape_round_white"
android:padding="20dp"
android:layout_marginTop="10dp"
android:layout_gravity="center"/>

Related articles: