ShapeDrawable

ShapeDrawable用于定义一个基本的几何图像(如,矩形、圆形、线条.......)。

定义ShapeDrawable的XML文件的根元素是<shape.../>,该元素可指定如下属性:

android:shape=["rectangle"|"oval"|"ling"|"ring"]——指定定义那种类型的几何图形。

实例如下:椭圆、渐变背景的文本框

drawable资源文件==》

myshape1.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:bottom="7dp"
android:left="7dp"
android:right="7dp"
android:top="7dp" />
<!-- 设置边框 -->
<stroke
android:width="3dip"
android:color="#ff0" /> </shape> myshape2.xml==>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" > <!-- 定义填充渐变色 angle,角度 -->
<gradient
android:angle="45"
android:endColor="#80FF00FF"
android:startColor="#FFFF0000" />
<!-- 设置四周的内边距 -->
<padding
android:bottom="7dp"
android:left="7dp"
android:right="7dp"
android:top="7dp" />
<!-- 设置圆角矩形 -->
<corners android:radius="8dp" /> </shape> myshape3.xml==>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval" > <!-- 定义填充渐变色 -->
<gradient
android:angle="45"
android:endColor="#00f"
android:startColor="#ff0"
android:type="sweep" />
<!-- 设置四周的内边距 -->
<padding
android:bottom="7dp"
android:left="7dp"
android:right="7dp"
android:top="7dp" />
<!-- 设置圆角矩形 -->
<corners android:radius="8dp" /> </shape> 布局文件==》
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" > <EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/myshape1" /> <EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/myshape2" /> <EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/myshape3" />
</LinearLayout>

运行效果:

android学习笔记33——资源ShapeDrawable的更多相关文章

  1. android学习笔记32——资源

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

  2. Android学习笔记菜单资源文件

    创建菜单资源 menu_one.xml <?xml version="1.0" encoding="utf-8"?> <menu xmlns: ...

  3. Android学习笔记样式资源文件

    样式资源和主题资源都是写在styles.xml文件里面的 <style name="title"> <item name="android:textSi ...

  4. Android学习笔记数组资源文件

    在android中我们可以通过数组资源文件,定义数组元素. 数组资源文件是位于values目录下的 array.xml <?xml version="1.0" encodin ...

  5. Android学习笔记尺寸资源

    尺寸资源语法 dp:设备独立资源像素 会根据设备匹配大小 一般用于设置边距和组件大小 sp : 可伸缩像素 根据用户手机字体大小首选项进行缩放 使用尺寸资源 定义尺寸资源 dimens <?xm ...

  6. Android学习笔记颜色资源文件

    资源文件目录 颜色资源文件格式 colors.xml <?xml version="1.0" encoding="utf-8"?> <reso ...

  7. 【转】Pro Android学习笔记(四):了解Android资源(下)

    处理任意的XML文件 自定义的xml文件放置在res/xml/下,可以通过R.xml.file_name来获取一个XMLResourceParser对象.下面是xml文件的例子: <rootna ...

  8. 【转】Pro Android学习笔记(三):了解Android资源(上)

    在Android开发中,资源包括文件或者值,它们和执行应用捆绑,无需在源代码中写死,因此我们可以改变或替换他们,而无需对应用重新编译. 了解资源构成 参考阅读Android学习笔记(三八):资源res ...

  9. Android学习笔记36:使用SQLite方式存储数据

    在Android中一共提供了5种数据存储方式,分别为: (1)Files:通过FileInputStream和FileOutputStream对文件进行操作.具体使用方法可以参阅博文<Andro ...

随机推荐

  1. 读metronic文档学到的几个知识点

    1.RTL  同样的页面,它做了两套.为什么,因为在这个世界上,有些民族,有些语种,是从右向左来的. 2. google material design 同样的一套东西,又分别做了google mat ...

  2. strong和b

    strong和b标签都是很久以前遗留下来的标签,b标签用来加粗字体,strong用来强调,通常浏览器会把强调的语句加粗,所以二者效果比较近似.语义化愈发受重视以后,b标签退出大众视野,strong依然 ...

  3. dll清理

    結束了閉關,又得與人類交流了,只好裝QQ 印象中企鵝手腳一向是BAT中最乾淨的-結果還是裝了不少樂色,一併挖出來除之   C:\program files\common files\tencent\q ...

  4. (单选后,显示相对应的div)点击免费没有变化,点击收费出现输入框

    <li> <label class="feiyonglabel">活动费用</label> <div class="textbo ...

  5. hdu 2795 线段树(二维问题一维化)

    Billboard Time Limit: 20000/8000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  6. 1-4-2 Windows数据类型与重要数据结构

    主要内容:介绍Windows数据类型与重要数据结构 1.数据类型 在Windows系统中定义了Windows应用程序中包含种类繁多的数据类型, 部分如下: WORD 16位无符号整数 typedef ...

  7. spark-scheduled调度算法

    1.3源码是如此,后面新版本源码会尽可能的根据用户shell配置的参数进行分配 1.spareadOutApps 尽可能分配到多的机器上面execute和CPU core 2.非spareadouta ...

  8. 关于setInterval()里的this和细节

    setInterval(fn,t);里的fn中,要使用外部类的this,则需要先将this保存起来,再使用保存的this,不能直接使用this,里面的this是指向window对象,记住setInte ...

  9. Python实现ORM

    ORM即把数据库中的一个数据表给映射到代码里的一个类上,表的字段对应着类的属性.将增删改查等基本操作封装为类对应的方法,从而写出更干净和更富有层次性的代码. 以查询数据为例,原始的写法要Python代 ...

  10. 黑马程序员——JAVA基础之简述 类的封装

    ------- android培训.java培训.期待与您交流! ---------- 类的封装(Encapsulation)  封装:是指隐藏对象的属性和实现细节,仅对外提供公共访问方式. 封装优 ...