Android項目實戰(三十六):給背景加上陰影製作效果

來源:互聯網
上載者:User

標籤:列表   高度   end   rtc   encoding   AC   lis   img   檔案   

原文:Android項目實戰(三十六):給背景加上陰影製作效果

 

圓角背景大家應該經常用:

一個drawable資源檔  裡面控制corner圓角 和solid填充色 

<shape xmlns:android="http://schemas.android.com/apk/res/android">    <corners android:radius="@dimen/dp_2"></corners>    <solid android:color="@color/standard_main"></solid></shape>

 

 那麼在此基礎上 , 實現帶陰影製作效果的圓角背景  

 代碼如下

<?xml version="1.0" encoding="utf-8"?><layer-list xmlns:android="http://schemas.android.com/apk/res/android" ><!-- 陰影部分 --><!-- 個人覺得更形象的表達:top代表下邊的陰影高度,left代表右邊的陰影寬度。其實也就是相對應的offset,solid中的顏色是陰影的顏色,也可以設定角度等等 --><item    android:left="4dp"    android:top="4dp">    <shape android:shape="rectangle" >        <gradient            android:angle="270"            android:endColor="#0F000000"            android:startColor="#0F000000" />        <corners            android:bottomLeftRadius="@dimen/dp_4"            android:bottomRightRadius="@dimen/dp_14"            android:topLeftRadius="@dimen/dp_4"            android:topRightRadius="@dimen/dp_4" />    </shape></item><!-- 背景部分 --><!-- 形象的表達:bottom代表背景部分在上邊緣超出陰影的高度,right代表背景部分在左邊超出陰影的寬度(相對應的offset) --><item    android:bottom="3dp"    android:left="@dimen/dp_0.5"    android:top="@dimen/dp_0.5"    android:right="3dp">    <shape android:shape="rectangle" >        <gradient            android:angle="270"            android:endColor="#FFFFFF"            android:startColor="#FFFFFF" />        <corners            android:bottomLeftRadius="@dimen/dp_4"            android:bottomRightRadius="@dimen/dp_14"            android:topLeftRadius="@dimen/dp_4"            android:topRightRadius="@dimen/dp_4" />    </shape></item></layer-list>

 效果: 可以看到 右側和下側都有一個小範圍的灰色陰影製作效果。

 

 

在實際產品中作為列表item的背景效果:

 

 是不是實現了一種類似cardview的效果 

 

Android項目實戰(三十六):給背景加上陰影製作效果

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.