`

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: ------------------------------------------- ...

    openssl各个版本

    - 近年来,由于安全性考虑,MD5 和 SHA-1 已经不再推荐使用,转而推荐更安全的 SHA-2 和 SHA-3 系列。 3. **SSL/TLS 协议**: - SSL(Secure Sockets Layer)是一种早期的安全协议,已由 TLS(Transport Layer ...

    allegro skill functions prefixed axl

    2. **`axl:get-layer-list`**: Returns a list of all layers in the current design. This is useful for iterating through different layers when performing operations that need to be applied to each layer ...

    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...

    STM32F103移值FreeRtos笔记 - 狗尾巴草word - 博客园1

    - `list.c`、`queue.c` 和 `tasks.c`:位于 `\FreeRTOS\Source`。 #### 4. 编写 main 函数 - **示例代码**: ```c #include "FreeRTOS.h" #include "task.h" #include "queue.h" #include "misc.h" #include...

    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...

    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 ...

    java面试题

    - JSP的`&lt;jsp:include&gt;`和`&lt;%@ include %&gt;`用于包含外部文件,前者运行时包含,后者编译时包含。 11. **J2EE相关知识** - J2EE是企业级Java应用平台,包括J2SE(标准版),J2ME(移动版)。 - Application ...

    ISO 14229-1-2013.pdf

    1. **Application Layer Services**: Defines the services provided by the application layer, including their format and data units. 2. **Application Layer Protocol**: Specifies the protocol used for ...

    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...

    myself notebook 14229

    Based on the given information from the file, it appears that the document is an international standard ISO 14229-1:2020, which pertains to application layer services, specifically within the context ...

    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 ...

    openssl库已经编译的文件

    OpenSSL 是一个强大的安全套接层 (SSL) 和 Transport Layer Security (TLS) 库,它包含各种加密算法、证书处理以及用于实现网络通信安全性的实用工具。标题提到的 "openssl库已经编译的文件" 意味着你已经拥有了预...

    1000道 互联网Java工程师面试题 485页

    MyBatis可以使用简单的XML或注解进行配置和原始映射,将接口和Java的POJOs(Plain Old Java Objects,普通的Java对象)映射成数据库中的记录。 #### 2、MyBatis的优点: - **强大的映射器引擎**:它能够将来自数据库...

    linux下用C写的基于SSL 的TCP例子代码!

    在Linux环境下,使用C语言编写基于SSL(Secure Socket Layer)的TCP程序是一项常见的任务,尤其在开发安全通信软件时。SSL是一种网络安全协议,用于在Internet上提供加密通信和身份验证。下面将详细介绍如何在Linux...

    PythonC API 3.9.1 参考手册.pdf

    2. **包含文件**:Python C API的核心是通过头文件`#include &lt;Python.h&gt;`来引入的,这个头文件包含了所有必要的定义和声明,使得C代码能够访问Python的内部结构和函数。 3. **有用的宏**:手册中介绍了大量宏,例如...

Global site tag (gtag.js) - Google Analytics