ShapeDrawable 用于定义一个基本的几何图形(如矩形、圆形、线条等),定义 ShapeDrawable 的 XML 文件的根元素是<shape.../>元素,该元素可指定如下属性。
示例:
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/my_shape_1"
/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/my_shape_2"
/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/my_shape_3"
/>
</LinearLayout>
my_shape_1.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- 设置填充颜色 -->
<solid android:color="#fff"/>
<!-- 设置四周的内边距 -->
<padding android:left="7dp"
android:top="7dp"
android:right="7dp"
android:bottom="7dp" />
<!-- 设置边框 -->
<stroke android:width="3dip" android:color="#ff0" />
</shape>
my_shape_2.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- 定义填充渐变颜色 -->
<gradient
android:startColor="#FFFF0000"
android:endColor="#80FF00FF"
android:angle="45"/>
<!-- 设置内填充 -->
<padding android:left="7dp"
android:top="7dp"
android:right="7dp"
android:bottom="7dp" />
<!-- 设置圆角矩形 -->
<corners android:radius="8dp" />
</shape>
my_shape_3.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<!-- 定义填充渐变颜色 -->
<gradient
android:startColor="#ff0"
android:endColor="#00f"
android:angle="45"
android:type="sweep"/>
<!-- 设置内填充 -->
<padding android:left="7dp"
android:top="7dp"
android:right="7dp"
android:bottom="7dp" />
<!-- 设置圆角矩形 -->
<corners android:radius="8dp" />
</shape>
 
 
 
 
 
 
 
 
 
 
 
 
 

ShapeDrawable 资源的更多相关文章

  1. 使用(Drawable)资源———ShapeDrawable资源

    ShapeDrawable用于定义一个基本的几何图形(如矩形.圆形.线条等),定义ShapeDrawable的XML文件的根元素是<shape.../>元素,该元素可指定如下属性. and ...

  2. Android中的Drawable资源

    在Android应用中,常常会用到Drawable资源,比如图片资源等,在Android开发中我们是用Drawable类来Drawable类型资源的. Drawable资源一般存储在应用程序目录的\r ...

  3. 样式(Style)和主题(Theme)资源——主题资源

    与样式资源非常相似,主题资源的XML文件通常也放在/res/values 目录下,主题资源的XML文档同样以<resources.../>元素作为根元素,同样使用<style.../ ...

  4. Android学习15--使用(Drawable)资源

    1.图片资源 图片资源是最简单的Drawable资源.仅仅要把*.png.*.jpg*..gif等格式的图片放入/res/drawable-XXX文件夹下,Android SDK就会在编译应用自己主动 ...

  5. Drawable资源的初步使用

    刚開始接触到Android的时候,看到类似以下的一个Button: 当时感觉这种button有点像Material Design风格.真的以为是裁剪好的图片,好奇心驱使我上网查找实现的方法,原来不是裁 ...

  6. android中常见的Drawable资源有哪些?

    Drawable资源是安卓应用中最常见的一种资源,比如图片等,因此,对于初学者而言,必须掌握drawable资源相关应用. 今天在网上刚好看到了一篇介绍android Drawable资源的文章,分享 ...

  7. android应用的资源

    应用资源可以分为两大类: 1.无法直接访问的原生资源,保存在asset目录下. 2.可以通过R资源清单类访问的资源,保存在res目录下. 资源的类型以及存储方式: android要求在res目录下用不 ...

  8. 疯狂Android讲义 - 学习笔记(五)

    第五章 Android使用统一的Intent对象来封装“启动意图”,不管是启动Activity.Service组件.或者BroadcastReceiver等,提供了一致的编程模型.Intent设计有点 ...

  9. Android开发学习清单

    目录: 第1章 Android应用与开发环境1.1 Android的发展和历史1.1.1 Android的发展和简介1.1.2 Android平台架构及特性1.2 搭建Android开发环境1.2.1 ...

随机推荐

  1. NOI2003 文本编辑器

    练手QAQ #include<iostream> #include<algorithm> #include<cstdio> #include<cstdlib& ...

  2. [Firebase] Deploy you website to Firebase

    If you are looking for a host website, you can try Firebase, heroku or AWS... Today, I tried to depl ...

  3. PermGen space错误解决方法

    在看下文之前,首先要确认意见事情,就是你是怎样启动tomcat的,我们在平时的开发环境其中,都是通过startup.bat方式启动tomcat的,那么你依照以下的方式,去改动/bin/catalina ...

  4. [转] Java中的访问控制

    可见/访问性 在同一类中 同一包中 不同包中  同一包子类中  不同包子类中   public  yes  yes  yes  yes  yes  protected   yes  yes  no   ...

  5. Java基础知识强化之IO流笔记17:FileOutputStream构造方法使用

    1. 可以参照之前写的笔记:   Android(java)学习笔记167:Java中操作文件的类介绍(File + IO流) 2. FileOutputStream(常用的)构造方法: FileOu ...

  6. MSSQLSERVER服务不能启动

    自从用上mysql,好久没打开sqlserver了,今天本想打开调试下MFC连接sqlserver,然后意外发现不能登录,之后我以为是sql服务没启动,然后去启动,还是没用,并且MSSQLSERVER ...

  7. CentOS6.6x86_64 部署 Nginx1.62+MySQL5.6.20+PHP5.6.4

    准备工作 切换到管理员身份 su - 安装编译扩展 yum install -y gcc-c++ 创建数据库目录.代码目录 mkdir /mnt/data /mnt/www 安装Nginx 1.6.2 ...

  8. redisbook笔记——redis内部数据结构

    在Redis的内部,数据结构类型值由高效的数据结构和算法进行支持,并且在Redis自身的构建当中,也大量用到了这些数据结构. 这一部分将对Redis内存所使用的数据结构和算法进行介绍. 动态字符串 S ...

  9. datazen 备份还原

    DataZen备份:   DataZen还原 第一步:用管理员进入dos,输入 net stop datazen 第二步:切换到datazen Core Service的安装目录cd c:\Progr ...

  10. [转帖]gesture recognition

    http://wenku.baidu.com/view/53c3331a6bd97f192279e9c9.html HSI与RGB的Matlab实现. http://wenku.baidu.com/v ...