Android控件 阴影效果

1. 定义layer-list的xml文件,设置背景

  
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >  

      
      
    <item  
        android:left="2dp"  
        android:top="2dp"  
        android:right="2dp"  
        android:bottom="2dp">  
        <shape android:shape="rectangle" >  

            <gradient  
                android:angle="270"  
                android:endColor="#0F000000"  
                android:startColor="#0F000000" />  

            <corners  
                android:bottomLeftRadius="6dip"  
                android:bottomRightRadius="6dip"  
                android:topLeftRadius="6dip"  
                android:topRightRadius="6dip" />  
        shape>  
    item>  

      
      
    <item  
        android:left="3dp"  
        android:top="3dp"  
        android:right="3dp"  
        android:bottom="5dp">  
        <shape android:shape="rectangle" >  

            <gradient  
                android:angle="270"  
                android:endColor="#FFFFFF"  
                android:startColor="#FFFFFF" />  

            <corners  
                android:bottomLeftRadius="6dip"  
                android:bottomRightRadius="6dip"  
                android:topLeftRadius="6dip"  
                android:topRightRadius="6dip" />  
        shape>  
    item>  
layer-list> 

2。使用ShadowLayout

添加依赖

Gradle:

    compile 'com.lijiankun24:shadowlayout:1.0.0'

Maven:

    <dependency>
      <groupId>com.lijiankun24</groupId>
      <artifactId>shadowlayout</artifactId>
      <version>1.0.0</version>
      <type>pom</type>
    </dependency>
 xml 布局文件实现
            <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@android:color/white"
            android:contentDescription="@null"
            android:src="@mipmap/ic_launcher"/>
    
3.ShadowViewHelper的使用
github 地址:https://github.com/wangjiegulu/ShadowViewHelper

compile 'com.github.wangjiegulu:ShadowViewHelper:1.0.1'
 ShadowViewHelper.bindShadowHelper(
                new ShadowProperty()
                        .setShadowColor(0x77FF0000)
                        .setShadowDy(3)
                        .setShadowRadius(3)
                , findViewById(R.id.linearlayout));

 其中

findViewById(R.id.linearlayout)可以是自己写的任意控件

你可能感兴趣的:(Android控件 阴影效果)