【移動(dòng)應(yīng)用開(kāi)發(fā)技術(shù)】Android中怎么設(shè)置陰影效果_第1頁(yè)
【移動(dòng)應(yīng)用開(kāi)發(fā)技術(shù)】Android中怎么設(shè)置陰影效果_第2頁(yè)
【移動(dòng)應(yīng)用開(kāi)發(fā)技術(shù)】Android中怎么設(shè)置陰影效果_第3頁(yè)
【移動(dòng)應(yīng)用開(kāi)發(fā)技術(shù)】Android中怎么設(shè)置陰影效果_第4頁(yè)
【移動(dòng)應(yīng)用開(kāi)發(fā)技術(shù)】Android中怎么設(shè)置陰影效果_第5頁(yè)
免費(fèi)預(yù)覽已結(jié)束,剩余2頁(yè)可下載查看

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

【移動(dòng)應(yīng)用開(kāi)發(fā)技術(shù)】Android中怎么設(shè)置陰影效果

這篇文章將為大家詳細(xì)講解有關(guān)Android中怎么設(shè)置陰影效果,文章內(nèi)容質(zhì)量較高,因此在下分享給大家做個(gè)參考,希望大家閱讀完這篇文章后對(duì)相關(guān)知識(shí)有一定的了解。給控件設(shè)置陰影,會(huì)使得界面元素更好看一寫(xiě),google給我們提供了一個(gè)現(xiàn)成的控CardView,可以將CardView看做是FrameLayout在自身之上添加了圓角和陰影效果本文是使用給控件設(shè)置背景實(shí)現(xiàn)陰影在res/drawable下新建一個(gè)DrawableResourceFile使用layer-list圖層就是說(shuō)可以多個(gè)圖層一層一層蓋上去新建一個(gè)漸變的圖層item作為背景圖層,主要是gradient,shape是用來(lái)定義形狀的,corners設(shè)置角度,gradient定義該形狀里面為漸變色填充,startColor起始顏色,endColor結(jié)束顏色,angle表示方向角度。當(dāng)angle=0時(shí),漸變色是從左向右。然后逆時(shí)針?lè)较蜣D(zhuǎn),當(dāng)angle=90時(shí)為從下往上<item

>

<shape

android:shape="rectangle"

>

<gradient

android:angle="90"

android:endColor="#dad9d9"

android:startColor="#03a430"

/>

<corners

android:radius="10dp"

/>

</shape>

</item>新建一個(gè)圖層,作為頂層圖層,陰影實(shí)現(xiàn)的原理,就是頂層的小顯示一點(diǎn),露出一部分下面的圖層,這個(gè)就需要設(shè)置Item的left,top,right,bottom屬性,這幾個(gè)參數(shù)的設(shè)置就類(lèi)似于設(shè)置margin,這樣就可以出來(lái)陰影效果了,當(dāng)然為了效果,我的參數(shù)設(shè)置的有點(diǎn)夸張,只設(shè)置了右邊和下邊的陰影,solid設(shè)置填充,還有stroke設(shè)置邊框,設(shè)置了顏色,設(shè)置了寬度就可以看見(jiàn)邊框效果了<item

>

<shape

android:shape="rectangle"

>

<gradient

android:angle="90"

android:endColor="#dad9d9"

android:startColor="#03a430"

/>

<corners

android:radius="10dp"

/>

</shape>

</item>

<item

android:right="20dp"

android:bottom="40dp">

<shape

android:shape="rectangle"

>

<solid

android:color="#FFFFFF"/>

<corners

android:radius="10dp"

/>

</shape>

</item>頂層的圖層上,還是可以添加觸摸的變化效果,即手指觸碰到該控件時(shí),控件背景色變化<item

android:right="2dp"

android:bottom="6dp">

<selector>

<item

android:state_focused="false"

android:state_pressed="true"

>

<shape

android:shape="rectangle"

>

<solid

android:color="@color/E5"/>

<corners

android:radius="10dp"

/>

</shape>

</item>

<item>

<shape

android:shape="rectangle"

>

<solid

android:color="@color/white"/>

<corners

android:radius="10dp"

/>

</shape>

</item>

</selector>

</item>使用:android:background=”@drawable/你的陰影xml文件”<LinearLayout

android:layout_width="match_parent"

android:layout_height="50dp"

android:background="@drawable/vcam_entry_border"

android:gravity="center"

android:orientation="vertical">

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:paddingRight="@dimen/common_measure_10dp"

android:textColor="@color/black_100"

android:text="啦啦啦啦,我有陰影"/>

</LinearLayout>附:完整的陰影xml代碼<?xml

version="1.0"

encoding="utf-8"?>

<layer-list

xmlns:android="/apk/res/android"

>

<!--

陰影部分

最下面一層

-->

<item

>

<shape

android:shape="rectangle"

>

<gradient

android:angle="90"

android:endColor="#777777"

android:startColor="#C5C5C5"

/>

<corners

android:radius="10dp"

/>

</shape>

</item>

<!--

背景部分

-->

<!--

形象的表達(dá):bottom

left

...

類(lèi)似于設(shè)置

margin

-->

<item

android:right="2dp"

android:bottom="6dp">

<selector>

<item

android:state_focused="false"

android:state_pressed="true"

>

<shape

android:shape="rectangle"

>

<solid

android:color="@color/E5"/>

<corners

android:radius="10dp"

/>

</shape>

</item>

<item>

<shape

android:shape="rectangle"

>

<solid

android:color="@color/white"/>

<corners

android:

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論