android drawable下自定义的xml文件各种形式汇总

本文介绍如何使用XML绘制各种图形元素,包括圆形、矩形、线条等,并展示如何定制UI元素如按钮、文本视图的效果。同时,还探讨了颜色渐变、动画制作及自定义进度条的方法。

1、我们需要画一个小圆圈shape=”oval”

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

    <solid android:color="@color/colorPrimary" />
    <corners android:topLeftRadius="10dp"
        android:topRightRadius="10dp"
        android:bottomLeftRadius="10dp"
        android:bottomRightRadius="10dp"
        />
</shape>

2、圆角textview

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

    <solid android:color="#fff7f3" />
    <corners
        android:bottomLeftRadius="4dp"
        android:bottomRightRadius="4dp"
        android:topLeftRadius="4dp"
        android:topRightRadius="4dp" />
</shape>

3、按钮点击效果选择

<?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android" android:enterFadeDuration="@android:integer/config_shortAnimTime" android:exitFadeDuration="@android:integer/config_mediumAnimTime">
    <item android:state_pressed="true">
        <shape>
            <solid android:color="@color/colorPrimaryDark"/>
        </shape>
    </item>
    <item android:state_focused="true">
        <shape>
            <solid android:color="@color/colorPrimaryDark"/>
        </shape>
    </item>
    <item>
        <shape>
            <solid android:color="@color/colorPrimary"/>
        </shape>
    </item>
</selector>

4、checkbox选中、未选中,自定义的图片

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@mipmap/cb_selected" android:state_checked="true"/>
    <item android:drawable="@mipmap/cb_selected" android:state_selected="true"/>
    <item android:drawable="@mipmap/cb_selected" android:state_pressed="true"/>
    <item android:drawable="@mipmap/cb_unselected"/>
</selector>

5、指定高度,画横线、竖线

<?xml version="1.0" encoding="utf-8"?>
<shape
    android:shape="rectangle"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <size android:height="@dimen/divider_line_height_small"/>
    <solid android:color="@color/divider"/>
</shape>


竖线:
<?xml version="1.0" encoding="utf-8"?>
<shape
    android:shape="rectangle"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <size android:width="@dimen/divider_line_height_small"/>
    <solid android:color="@color/divider"/>
</shape>

6、SVG是一种矢量图格式,是Scalable Vector Graphics三个单词的首字母缩写。在xml文件中的标签是,画出的图形可以像一般的图片资源使用

<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24dp"
        android:height="24dp"
        android:viewportHeight="32.0"
        android:viewportWidth="32.0">
    <path
        android:fillColor="#666"
        android:pathData="m31.84 13.35c-0.31 0.57 -1 0.76 -1.54 0.43l-1.01 -0.61c-0.42 0.9 -0.98 1.86 -1.73 2.77l0.91 0.95c0.44 0.46 0.44 1.21 0 1.67c-0.44 0.46 -1.16 0.46 -1.6 0l-0.93 -0.97c-0.9 0.76 -2 1.43 -3.3 1.96l0.34 1.33c0.16 0.63 -0.2 1.28 -0.8 1.45c-0.6 0.17 -1.22 -0.21 -1.38 -0.84l-0.32 -1.24c-0.99 0.24 -2.08 0.41 -3.27 0.49v2.04c0 0.66 -0.5 1.2 -1.11 1.2c-0.61 0 -1.11 -0.54 -1.11 -1.2v-2.1c-1.36 -0.14 -2.56 -0.4 -3.64 -0.75l-0.38 1.52c-0.16 0.64 -0.77 1.02 -1.36 0.85c-0.59 -0.17 -0.94 -0.83 -0.78 -1.47l0.43 -1.75c-1.14 -0.59 -2.1 -1.3 -2.89 -2.06l-1.35 1.47c-0.43 0.47 -1.13 0.47 -1.57 0c-0.43 -0.47 -0.43 -1.23 0 -1.7l1.41 -1.52c-0.65 -0.92 -1.13 -1.85 -1.48 -2.72l-1.72 1.08c-0.53 0.33 -1.21 0.13 -1.51 -0.44c-0.31 -0.57 -0.12 -1.31 0.41 -1.64l1.92 -1.2c0.06 -0.04 0.13 -0.07 0.2 -0.1c-0.1 -0.45 -0.16 -0.81 -0.19 -1.07h-0.04c0 -0.07 0.01 -0.13 0.02 -0.2c-0.01 -0.13 -0.02 -0.2 -0.02 -0.2h0.07c0.15 -0.46 0.56 -0.8 1.04 -0.8c0.48 0 0.89 0.34 1.04 0.8h0.07c2.22 9.69 11.82 9.6 11.82 9.6c0 0 9.6 -0 11.82 -9.59h0.06c0.15 -0.47 0.56 -0.81 1.04 -0.81c0.49 0 0.89 0.34 1.04 0.81h0.07c0 0 -0.01 0.07 -0.02 0.2c0.01 0.06 0.02 0.13 0.02 0.19h-0.04c-0.05 0.37 -0.15 0.98 -0.36 1.74l1.32 0.8c0.54 0.33 0.73 1.05 0.41 1.62z"/>
</vector>

是不是很羡慕这些酷酷的图形,当然自己也可以去动手去做。显而易见,上面例子的重点是在PathData里面的那一大窜数字:

android:pathData="M22,16V4c0,-1.1 -0.9,-2 -2,-2H8c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2zm-11,-4l2.03,2.71L16,11l4,5H8l3,-4zM2,6v14c0,1.1 0.9,2 2,2h14v-2H4V6H2z" />

http://www.cnblogs.com/yuhanghzsd/p/5466846.html

7、rating bar自定义图片,空白-半星-全星

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item
        android:id="@android:id/background"
        android:drawable="@mipmap/ic_empty_star" />

    <item
        android:id="@android:id/secondaryProgress"
        android:drawable="@mipmap/ic_half_star" />

    <item
        android:id="@android:id/progress"
        android:drawable="@mipmap/ic_star" />

</layer-list>

8、xml里面引用其他的xml

1、
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/laevatein_button_background_count_pressed" android:state_pressed="true"/>
    <item android:drawable="@drawable/laevatein_button_background_count_disable" android:state_enabled="false"/>
    <item android:drawable="@drawable/laevatein_button_background_count_normal"/>
</selector>

引用1:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <corners android:radius="6dp"/>
            <solid android:color="@color/colorPrimaryDark"/>
        </shape>
    </item>
</layer-list>

引用2:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <corners android:radius="6dp"/>
            <solid android:color="#bbbbbb"/>
        </shape>
    </item>
</layer-list>

引用3:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <corners android:radius="6dp"/>
            <solid android:color="@color/colorPrimary"/>
        </shape>
    </item>
</layer-list>

9、button点击效果全面

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

    <item android:state_enabled="true" android:state_focused="true" android:state_pressed="false">

        <shape>
            <solid android:color="#e0b419" />
            <corners android:radius="12dp"/>
        </shape>

    </item>

    <item android:state_enabled="true" android:state_pressed="true">

        <shape>
            <solid android:color="#e0b419" />
            <corners android:radius="12dp"/>
        </shape>
    </item>

    <item android:state_checked="true" android:state_enabled="true">
        <shape>
            <solid android:color="#e0b419" />
            <corners android:radius="12dp"/>
        </shape>
    </item>

    <item android:state_enabled="false">
        <shape>
            <solid android:color="#bbbbbb" />
            <corners android:radius="12dp"/>
        </shape>
    </item>

    <item>
        <shape>
            <solid android:color="#e0b419" />
            <corners android:radius="12dp"/>
        </shape>
    </item>
</selector>

10、颜色渐变,从某个角度开始,默认左边-右边

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

 <gradient
     android:startColor="@color/white"
     android:endColor="@color/line_shadow"
     android:angle="270"
     />
</shape>

android:angle
Integer,代表渐变颜色的角度, 0 is left to right, 90 is bottom to top. 必须是45的整数倍. 
http://blog.csdn.net/zjdyhant/article/details/46537647

11、画圆 半径5dp

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

    <solid android:color="@color/red" />
    <size
        android:width="10dp"
        android:height="10dp" />
</shape>

12、声音大小动画

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:drawable="@mipmap/progress_voice_01"
        android:duration="500" />
    <item
        android:drawable="@mipmap/progress_voice_02"
        android:duration="500" />
    <item
        android:drawable="@mipmap/progress_voice_03"
        android:duration="500" />
</animation-list>

13、radio button

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@mipmap/radio_bt_selected" android:state_checked="true" />
    <item android:drawable="@mipmap/radio_bt_selected" android:state_selected="true" />
    <item android:drawable="@mipmap/radio_bt_selected" android:state_pressed="true" />
    <item android:drawable="@mipmap/radio_bt_unselected" />
</selector>

14、渐变色 左边—右边

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

    <gradient
        android:angle="0"
        android:endColor="?attr/colorPrimary"
        android:startColor="?attr/colorAccent"/>
</shape>

15、item点击变色

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@color/grey_light" android:state_pressed="true" />
    <item android:drawable="@color/grey_light" android:state_selected="true" />
    <item android:drawable="@android:color/transparent" />

</selector>

16、progressbar 进度条 和背景

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

    <!-- 背景  gradient是渐变,corners定义的是圆角 -->
    <item android:id="@android:id/background">
        <shape>
            <solid android:color="#00000000" />
        </shape>
    </item>

    <!-- 进度条 -->
    <item android:id="@android:id/progress">
        <clip>
            <shape>
                <gradient
                    android:angle="0"
                    android:endColor="?attr/colorPrimary"
                    android:startColor="?attr/colorAccent"/>
            </shape>
        </clip>
    </item>

</layer-list>
使用:
   <ProgressBar
        android:id="@+id/progress_bar"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="match_parent"
        android:layout_height="4dp"
        tools:progress="20"
        android:progressDrawable="@drawable/web_progressbar"
        />

17、button选中效果全面

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

    <item android:state_enabled="true" android:state_focused="true" android:state_pressed="false">

        <shape>
            <gradient android:angle="0" android:endColor="?attr/colorPrimary" android:startColor="?attr/colorAccent" />
            <corners android:bottomLeftRadius="5dp" android:bottomRightRadius="5dp" android:topLeftRadius="5dp" android:topRightRadius="5dp" />
        </shape>

    </item>

    <item android:state_enabled="true" android:state_pressed="true">

        <shape>
            <gradient android:angle="0" android:endColor="@color/colorPrimaryPressed" android:startColor="@color/colorAccentPressed" />
            <corners android:bottomLeftRadius="5dp" android:bottomRightRadius="5dp" android:topLeftRadius="5dp" android:topRightRadius="5dp" />
        </shape>
    </item>

    <item android:state_checked="true" android:state_enabled="true">
        <shape>
            <gradient android:angle="0" android:endColor="@color/colorPrimaryPressed" android:startColor="@color/colorAccentPressed" />
            <corners android:bottomLeftRadius="5dp" android:bottomRightRadius="5dp" android:topLeftRadius="5dp" android:topRightRadius="5dp" />
        </shape>
    </item>

    <item android:state_enabled="false">
        <shape>
            <gradient android:angle="0" android:endColor="@color/colorPrimaryDisabled" android:startColor="@color/colorAccentDisabled" />
            <corners android:bottomLeftRadius="5dp" android:bottomRightRadius="5dp" android:topLeftRadius="5dp" android:topRightRadius="5dp" />
        </shape>
    </item>

    <item>
        <shape>
            <gradient android:angle="0" android:endColor="?attr/colorPrimary" android:startColor="?attr/colorAccent" />
            <corners android:bottomLeftRadius="5dp" android:bottomRightRadius="5dp" android:topLeftRadius="5dp" android:topRightRadius="5dp" />
        </shape>
    </item>
</selector>
程序(program)是为实现特定目标或解决特定问题而用计算机语言编写的命令序列的集合。   程序(港台称之为程式) program(me)或procedure   chéng xù   概念1.:为进行某活动或过程所规定的途径。   概念2.程序是由序列组成的,告诉计算机如何完成一个具体的任务。由于现在的计算机还不能理解人类的自然语言,所以还不能用自然语言编写计算机程序。   指示计算机按解决问题的步骤   实现预期目的而进行操作的一系列语句指令。一般分为系统程序应用程序两大类。 计算机中的程序在港澳台地区称为程式。程序就是为使电子计算机执行一个或多个操作,或执行某一任务,按序设计的计算机指令的集合。由程序计数器(Program Counter)控制。程序(program)是为实现特定目标或解决特定问题而用计算机语言编写的命令序列的集合。是用汇编语言、高级语言等开发编制出来的可以运行的文件,在计算机中称可执行文件(后缀名一般为.exe)。我们玩的游戏一般都是应用程序(但现在后缀名为.swf的Flash影片类的游戏也比较流行)   常见的编程语言   * .NET   * ActionScript   * APL、A+J   * Ada   * 汇编语言   * AWK   * Basic   o QBasic   o Visual Basic   * VBScript   * Brainfuck   * C、C++   o Objective-C   * Clipper   * COBOL   * dBase   * PASCAL、Delphi   * Forth   * Fortran   * FoxPro   * F#   * Fava   * IDL   * Java   * JavaScript   * J#   * LISP   * Lua   * LOGO   * Modula   * Nuva   * Perl   * PHP   * PL/I   * Prolog   * Python   * R   * Ruby   * Scheme   * Smalltalk   * Tcl/Tk   * Visual FoxPro   怎样成为一名程序员   第一阶段:掌握一种编程语言   学习内容:学习任意一种主流的编程语言。例如C++语言。   学习目标:熟练掌握一种语言的语法基本的编程技巧。   学习时间:3个月左右   注意事项:编程语言编程工具是两回事情,编程语言是指C++、Basic、Object Pascal等。程序设计语言,它们是像汉语、英语一样的抽象的语法规则,编程工具是指 Visual C++ 6.0、Visual Basic 6.0、Delphi 7.0等包括了源代码编辑器、程序编译器 ,在内的集成化、可视化的软件开发工具。C++源程序可以在Visual C++ 6.0里编写,也可以在记事本里编写,而同一个C++源程序可以用Visual C++ 6.0编译、执行,也可以用C++ Builder 5.0编译、执行,所以: C++ 不等于 Visual C++ 6.0 。   第二阶段:掌握一种编程工具   学习内容:学习任意一种主流的编程工具。注意编程工具要第一阶段学习的编程语   言一致,例如你学习的编程语言是C++,那么编程工具要选Visual C++ 6.0、C++ Builder 5.0。   学习目标:熟练掌握这种编程工具基本用法,例如:菜单、组件、程序跟踪调试、编写Windows程序等。   学习时间:3个月左右   注意事项:这个阶段侧重编程工具的使用,同时进一步熟习编程语言,最后达到能熟练编写各种基本的Windows程序。   第三阶段:掌握“算法与数据结构”这门课程   学习内容:算法与数据结构,推荐许卓群的《数据结构》,高等教育出版社出版。   学习目标:熟练掌握各种常用的算法与数据结构   学习时间:4个月左右   注意事项:这是一门不可或缺的软件开发课程,曾经有一本经典计算机专业书籍叫做《数据结构+算法=程序》,这说明了数据结构算法的重要性。它能帮我们建立良好的程序分析与设计能力。   第四阶段:实现一个模拟的小型软件项目   学习内容:软件项目的开发过程   学习目标:掌握软件项目的基本开发过程方法   学习时间:4个月左右   注意事项:自己完成一个模拟的小型软件项目,强烈推荐做一个MIS(管理信息系统)软件,参考用书推荐:   1、“中小型信息管理系统开发实例系列丛书”,人民邮电出版社,它的例子详实有效。   2、 以它为基础再加以扩展,就可以做出实用的MIS软件来。   3、此丛书包括多种开发工具,大家可以选择适合自己的:《VISUAL FOXPRO6.0 数据库系统开发实例导航》   4、《JAVA数据库系统开发实例导航》 《VISUAL BASIC数据库系统开发实例导航》。   5、《VISUAL C++6.0数据库系统开发实例导航》 《ASP.NET数据库管理系统开发实例导航》   6、《DELPHI数据库系统开发实例导航》 《POWERBUILDER 8.0数据库系统开发实例导航》。 [编辑本段]社会上办事程序的定义 工作程序|按程序进行。   程序,是现在最吃香的提法。   [1]任何单位任何事情,首先强调的就是程序,因为管理界有句名言:细节决定成败。程序就是整治细节最好的工具。于是,现在我们的所有工作,无时无处不在强调程序。 因为有了规范的办事程序,现在我们这些平民百姓到政府机关办事比原来容易了许多,最起码知道办什么事该找哪个部门,知道办这个事应该用多长时间了。政府公开办事程序,也拉近了人民群众的关系。好,这是好得很的事。 好像是为了印证事物都是一分为二的道理一样,在赞颂程序的同时,我们也看到了程序冷酷的另一面。南宁见义勇为的英雄鲍光蛇在医院冷酷的程序中流尽了最后一滴血,公路收费站的值班人员因救护车交不出十元钱的过路费而坚决不放行救护车,终于使急需救助的患者丧命,……等等的例子,都为我们强调或者说奉为神圣规则的程序优先勾画出了它的原形。   程序,是管理方式的一种,是能够发挥出协调高效作用的工具,在我们的社会主义建设事业或者说现代化建设中,应该充分重视它的作用,应该不断地将我们的工作从无序整改到有序。   可是,当我们只关注形式而不关注实质的时候,有些事情就发展到了它的反面。程序不是医治百病的灵丹妙药,在它走向反面的时候,它是使那些官僚主义者视劳苦大众利益如不见的人们推脱掉自己应当承担的责任的最好的挡箭牌。因为越是严密完善的程序,按部就班执行起来越是要付出时间的代价,当时间被浪费了时候,因此引发的其他损失是不应该由模范执行了程序的人来负责的。 [编辑本段]程序的运行   为了一个程序运行,计算机加载程序代码,可能还要加载数据,从而初始化成一个开始状态,然后调用某种启动机制。在最低层上,这些是由一个引导序列开始的。   在大多数计算机中,操作系统例如视窗等,加载并且执行很多程序。在这种情况下,一个计算机程序是指一个单独的可执行的映射,而不是当前在这个计算机上运行的全部程序。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值