Details of Android layer list properties and usage

Android layer list is used to stack multiple layers for display. With this feature, you can make some special effects (such as shadows, the following effects, etc.) or take advantage of opportunism.

1. code chip

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >  
  3.       
  4. <! -- in recent projects, mu lt iple layers need to be stacked together, so we need to research
  5. Take a look at the layer list in android. Layer list in android
  6. It is used to stack multiple layers. >
  7.     <item>  
  8. < Shape > <! -- the color of the first layer is blue -- >
  9.           <solid android:color="@color/blue"/>  
  10.       </shape>  
  11.     </item>  
  12.       
  13. <! -- the color of the second layer, that is, the top layer, because the second layer is relative to the
  14. The bottom of the View moves up two DPS, so the first layer will show a dp black, so
  15. Give the illusion that there is only a bottom border -- >
  16.     <item android:bottom="2dip">  
  17.         <shape>  
  18.             <solid android:color="@color/white"/>  
  19.         </shape>  
  20.     </item>  
  21.   
  22. </layer-list>  

2. Layout code and renderings (be sure to write the id of RadioButton when using RadioGroup, otherwise you cannot switch)

  1. <RadioGroup  
  2.     android:id="@+id/rg"  
  3.     android:layout_below="@id/bt2"  
  4.     android:layout_margin="10dip"  
  5.     android:layout_width="match_parent"  
  6.     android:layout_height="wrap_content"   
  7.     android:orientation="horizontal">  
  8.           
  9.         <RadioButton   
  10.         android:id="@+id/rb0"  
  11.         android:layout_height="wrap_content"  
  12.         android:layout_width="0dip"  
  13.         android:layout_weight="1"  
  14.         android:button="@null"  
  15.         android:text="classification"  
  16.         android:checked="true"  
  17.         android:gravity="center"  
  18.         android:textColor="@color/black"  
  19.         android:background="@drawable/ch_bg"  
  20.         android:layout_marginTop="2dip"  
  21.         android:paddingBottom="4dip"/>  
  22.           
  23.         <RadioButton   
  24.         android:id="@+id/rb1"  
  25.         android:layout_height="wrap_content"  
  26.         android:layout_width="0dip"  
  27.         android:layout_weight="1"  
  28.         android:text="classification"  
  29.         android:button="@null"  
  30.         android:gravity="center"  
  31.         android:textColor="@color/black"  
  32.         android:background="@drawable/ch_bg"  
  33.         android:layout_marginTop="2dip"  
  34.         android:paddingBottom="4dip"/>  
  35.           
  36. </RadioGroup>  

selector

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <selector xmlns:android="http://schemas.android.com/apk/res/android" >  
  3.     <item android:state_checked="true" android:drawable="@drawable/bg_li"></item>  
  4.     <item android:state_checked="false" android:drawable="@color/white"></item>  
  5. </selector>  

Design sketch


3. code chip

  1. <?xml version="1.0dip" encoding="utf-8"?>  
  2. <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >  
  3.       
  4.     <item>  
  5.         <bitmap android:src="@drawable/ic_launcher"  
  6.             android:gravity="center"/>  
  7.     </item>  
  8.     <item android:left="10dip" android:top="10dip">  
  9.         <bitmap android:src="@drawable/ic_launcher"  
  10.             android:gravity="center"/>  
  11.     </item>  
  12.     <item android:left="20dip" android:top="20dip">  
  13.         <bitmap android:src="@drawable/ic_launcher"  
  14.             android:gravity="center"/>  
  15.     </item>  
  16.     <item android:left="30dip" android:top="30dip">  
  17.         <bitmap android:src="@drawable/ic_launcher"  
  18.             android:gravity="center"/>  
  19.     </item>  
  20.   
  21. </layer-list>  

Design sketch


4. code chip

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >  
  3.       
  4.     <item android:drawable="@drawable/ic_launcher"></item>  
  5.     <item android:left="10dip" android:top="10dip" android:drawable="@drawable/ic_launcher"></item>  
  6.     <item android:left="20dip" android:top="20dip" android:drawable="@drawable/ic_launcher"></item>  
  7.     <item android:left="30dip" android:top="30dip" android:drawable="@drawable/ic_launcher"></item>  
  8.   
  9. </layer-list>  

5. Knowledge base connection:

http://blog.csdn.net/brokge/article/details/9713041
http://www.aitinan.com/4004.html
http://www.cnblogs.com/tsoorr/p/3407935.html
http://www.cnblogs.com/ithouge/articles/ithouge-android-layer-list-shape-corners.html
http://www.linuxidc.com/Linux/2012-05/59827.htm


Reprint address: http://blog.csdn.net/pcaxb/article/details/47781547

Tags: Android xml encoding Linux

Posted on Wed, 01 Apr 2020 02:23:35 -0700 by servo