欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android給布局、控件加陰影效果的示例代碼

 更新時間:2017年11月30日 16:53:14   作者:費(fèi)城之鷹  
本篇文章主要介紹了Android給布局、控件加陰影效果的示例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

增加陰影效果,讓控件或者布局看起來有立體的效果,總的來說有兩種解決方案。

1,直接使用屬性: android:elevation="4dp"這樣一句代碼,就實(shí)現(xiàn)了效果,elevation表示海拔,就是布局的z軸的高度,調(diào)整高度,可以選擇陰影的輕重。

<TextView 
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center"
        android:elevation="4dp"
        android:background="@drawable/home_waitcourse_yellow_shape"
        android:textColor="@color/foorYellow"  
        android:text="報道"/>

2,這種方式就需要寫點(diǎn)代碼了,但是也不多,是通過寫一個xml來實(shí)現(xiàn)的。

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

  <!-- 陰影部分 --> 
  <!-- 個人覺得更形象的表達(dá):top代表下邊的陰影高度,left代表右邊的陰影寬度。其實(shí)也就是相對應(yīng)的offset,solid中的顏色是陰影的顏色,也可以設(shè)置角度等等 --> 
  <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> 

  <!-- 背景部分 --> 
  <!-- 形象的表達(dá):bottom代表背景部分在上邊緣超出陰影的高度,right代表背景部分在左邊超出陰影的寬度(相對應(yīng)的offset) --> 
  <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> 

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論