`

layer-list和include的使用

阅读更多
layer-list,include,merge使用,记录一下
转自:http://wang-peng1.iteye.com/blog/558646,
http://developer.android.com/guide/topics/resources/drawable-resource.html#LayerList

layer-list是一个静态的展示,selector是一个动态的展示。
当我们想把多个图层叠在一起现身的时候,可以使用layer-list,第一个item排在最下层,第二个item排在上面,当然还可以排三层、四层......,item之间最好产生距离,不然上层的会挡住下层的,字面上是多个层,也就是你可以把多个layer放在一起然后一其显现出来 如qqw.xml

1.代码实现方式:
Resources r = getResources(); 
Drawable[] layers = new Drawable[2]; 
layers[0] = r.getDrawable(R.drawable.cor_info); 
layers[1] = r.getDrawable(R.drawable.icon); 
LayerDrawable layerDrawable = new LayerDrawable(layers); 
((ImageView) findViewById(R.id.imageview)).setImageDrawable(layerDrawable);


2.layer-list.xml方式:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!--  
<item android:id="@+id/user_face_drawable" android:drawable="@drawable/h001"
	android:left="10.0dip" android:top="18.0dip" android:right="25.0dip"
	android:bottom="35.0dip" />
	-->
	<item>
		<shape>
			<solid android:color="#FF00ff00" />
			<gradient android:useLevel="true" android:type="sweep"
				android:startColor="#ff000000" android:endColor="#ffff0000" />
		</shape>
	</item>
	<item>
		<rotate android:pivotX="50%" android:pivotY="50%"
			android:fromDegrees="0" android:toDegrees="80" 
			android:drawable="@drawable/icon" />
	</item>
</layer-list>


然后就可以在别处引用了

<ImageButton android:id="@+id/btnFindMe"  
    android:layout_width="wrap_content"  
    android:layout_height="wrap_content" 
    android:layout_centerInParent="true"
    android:background="@drawable/qqw"/>


例如在 android:style/Widget.ProgressBar.Large 或者其他的progressbar风格

<style name="progressBarStyleSmall" parent="android:style/Widget.ProgressBar.Large">
<item name="android:indeterminateDrawable">@drawable/progress</item>
</style>


<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
   <!--   <item android:drawable="@android:drawable/progress_circular_background" />-->
     <!--  <item>
        <shape android:shape="ring"
               android:innerRadiusRatio="3.4"
               android:thicknessRatio="6.0">
            <gradient
                   android:useLevel="true"
                   android:type="sweep"
                   android:startColor="#ff000000"
                   android:endColor="#ffffffff" />
        </shape>  
    </item> -->
    <item>
        <rotate
            android:pivotX="50%" android:pivotY="50%"
            android:fromDegrees="0" android:toDegrees="370"
            android:drawable="@drawable/load2" />
    </item>
</layer-list>


而include的使用就是为了降低 重复书写同一个布局而使用的引用,当然他还有另一优点就是和merge的混合使用 当你想添加一个布局而这个布局本身已经有了一个layout你想直接在这个layout下添控件,而你另一个xml中必须有一个layout ,如果你直接引用include这个xml那么就会多了一个layout ,所以这时候你应该把控件填写在merge中,这样就可以直接加入到原来的layout中了。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="64dip"
    android:gravity="center_vertical"
    android:ignoreGravity="@+id/icon">
    <include layout="@layout/track_list_item_common" />;
</RelativeLayout>


track_list_item_common.xml
<merge xmlns:android="http://schemas.android.com/apk/res/android">
 
    <ImageView android:id="@+id/icon"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:layout_marginLeft="4dip"
        android:layout_width="60px"
        android:layout_height="60px"/>
...
</merge>


从上面的代码可以看到 merge是不需要merge的
分享到:
评论

相关推荐

    occam一维反演

    C OF THE MODEL, SUCH AS LAYER THICKNESSES, FINITE ELEMENT MESH, ETC. COMMUNICATION C BETWEEN INPUTM() AND FORMOD() AND FORDIV() MUST BE VIA THE USER'S OWN COMMON C BLOCKS. WITH STATIC COMMONS (CHECK ...

    Senfore_DragDrop_v4.1

    Please include the words "Drag Drop" in the subject of any email regarding these components. ------------------------------------------- 6. Bug reports: ------------------------------------------- ...

    FlexGraphics_V_1.79_D4-XE10.2_Downloadly.ir

    (FActionIndex could appear beyond the list boundaries). Thanks to Giedrius Matonis. - ADD: Added the method TCustomProp.Assign - a source flex-property is written to stream, which is then read by...

    opensc-0.12.0.tar.gz

    * pkcs11-tool can use a slot based on ID, label or index in the slot list. * PIN flags are updated from supported cards when C_GetTokenInfo is called. * Support for CardOS 4.4 cards added. * Fature to...

    MPEG Video Wizard

    The main features include 1. frame accurate editing for cut, copy, paste, and record. 2. insert simple transitions with video special effect. 3. an integrated text and graphics title editor. 4. ...

    Bochs - The cross platform IA-32 (x86) emulator

    - Include win64 native binary in the release. - Fixed failures on big endian hosts. - BIOS: Support for up to 2M ROM BIOS images. - GUI: select mouse capture toggle method in .bochsrc. - Ported most...

    acpi控制笔记本风扇转速

    list (if present) is now obtained and also checked for an ID match. Implemented additional support for the PCI _ADR execution: upsearch until a device scope is found before executing _ADR. This ...

    3G EVOLUTION HSPA AND LTE FOR MOBILE BROADBAND_2nd_edition

    Keytechnologies presented include multi-carrier transmission, advancedsingle-carrier transmission, advanced receivers, OFDM, MIMO andadaptive antenna solutions, advanced radio resource management ...

    php.ini-development

    ;;;;;;;;... 1.... 2.... 3.... 4.... 5.... 6.... The syntax of the file is extremely simple.... Section headers (e.g.... at runtime.... There is no name validation.... (e.g.... previously set variable or directive (e.g....

    Rave Player网页视频播放器

    - Added m4v extension to video list. v2.0.14 (Nov. 12, 2009) - If wimpyApp contains a "?" then replace startupdirlist "?" with a "&". v2.0.13 (Nov. 12, 2009) - Added linkToWindow feature and ...

    ap6212a0_a33_sc3817r_服务器验证通过_bt已经通了_wifi需要修改配置_需要再次验证_20170626_1549.7z

    #include device/softwinner/polaris-common/prebuild/google/products/gms_base.mk 4、 R:\wyb\ap6212a0_a33_sc3817r\android\device\softwinner\astar-y3\BoardConfig.mk # wifi and bt configuration # 1. ...

    DIContainers v5.7.0 D7-XE10.1 容器

    Structure describes the arrangement of items within the container, like linked list, linear vector, etc. The structure determines how quickly items can be added, manipulated and retrieved from the ...

    ap6212a0_a33_sc3817r_神舟验证版本_借用nvram_ap6210这个配置文件_20170626_1834没有外层目录.7z

    #include device/softwinner/polaris-common/prebuild/google/products/gms_base.mk 4、 R:\wyb\ap6212a0_a33_sc3817r\android\device\softwinner\astar-y3\BoardConfig.mk # wifi and bt configuration # 1. ...

    !!!!ap6212a0_a33_sc3817r_验证通过_修正wifi的配置文件为nvram_ap6212.txt

    #include device/softwinner/polaris-common/prebuild/google/products/gms_base.mk 4、 Q:\a33\ap6212a0_a33_sc3817r\android\device\softwinner\astar-y3\BoardConfig.mk # wifi and bt configuration # 1. ...

    FCKeditor-test

    &lt;#include "/static/scripts/headIframe.ftl"/&gt; &lt;table width="100%" cellpadding="0" cellspacing="0" class="list_box1"&gt; ${base}/static/scripts/tinymce/jscripts/tiny_mce/tiny_mce.js"&gt; tinyMCE.init({ // ...

    ap6212a0_bb16v3_sina33验证通过BT的功能_wifi部分有问题_20170626_1148没有外层目录.7z

    #include device/softwinner/polaris-common/prebuild/google/products/gms_base.mk 4、 R:\wyb\ap6212a0_a33_sc3817r\android\device\softwinner\astar-y3\BoardConfig.mk # wifi and bt configuration # 1. ...

    计算机网络第六版答案

    23. The five layers in the Internet protocol stack are – from top to bottom – the application layer, the transport layer, the network layer, the link layer, and the physical layer. The principal ...

    Dreamweaver CS4 黄金插件10-1

    LIST: 1. A Simple Poll V2.0.0 For Adobe Dreamweaver 2. Abrir Janela Pop-Up V1.0.2 (Portuguese) For Adobe Dreamweaver 3. Add Gradient Background Style V1.0.0 For Adobe Dreamweaver 4. Add onmouseout V...

    黄永刚单晶塑性有限元umat子程序

    4 celent,dfgrd0,dfgrd1,noel,npt,layer,kspt,kstep,kinc) c WRITE (6,*) ' c NOTE: MODIFICATIONS TO *UMAT FOR ABAQUS VERSION 5.3 (14 APR '94) c c (1) The list of variables above defining the *UMAT ...

    Dreamweaver CS4 黄金插件10-02

    6. Advanced CSS File Include V1.0.0 For Adobe Dreamweaver 7. Advanced Manage Workspace Layouts V1.1.1 For Adobe Dreamweaver 8. Advanced Random Images V4.3.8 For Adobe Dreamweaver 9. ASP Random Images ...

Global site tag (gtag.js) - Google Analytics