Android中的Drawable资源—— GradientDrawable
2016-06-14 16:21
405 查看
ShapeDrawable 根据原始的形状来绘制图形,如矩形,圆形,线条等,可以是一个纯色的色块,也可以渐变的效果。当没有设置具体的图形时,默认为矩形。
它对应的是一个GradientDrawable对象。
例如:
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape=["rectangle" | "oval" | "line" | "ring"] > <corners android:radius="integer" android:topLeftRadius="integer" android:topRightRadius="integer" android:bottomLeftRadius="integer" android:bottomRightRadius="integer" /> <gradient android:angle="integer" android:centerX="float" android:centerY="float" android:centerColor="integer" android:endColor="color" android:gradientRadius="integer" android:startColor="color" android:type=["linear" | "radial" | "sweep"] android:useLevel=["true" | "false"] /> <padding android:left="integer" android:top="integer" android:right="integer" android:bottom="integer" /> <size android:width="integer" android:height="integer" /> <solid android:color="color" /> <stroke android:width="integer" android:color="color" android:dashWidth="integer" android:dashGap="integer" /> </shape>
它对应的是一个GradientDrawable对象。
例如:
<?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>
<TextView android:background="@drawable/gradient_box" android:layout_height="wrap_content" android:layout_width="wrap_content" />
Resources res = getResources(); Drawable shape = res. getDrawable(R.drawable.gradient_box); TextView tv = (TextView)findViewByID(R.id.textview); tv.setBackground(shape);
相关文章推荐
- android开发常用快捷键
- Android将Activity打成jar包供第三方调用(解决资源文件不能打包的问题)
- Android自定义View的实现方法,带你一步步深入了解View
- Android:控件布局(相对布局)RelativeLayout
- Android Debug Bridge(ADB)的用法
- 关于layout布局中的变量
- Android中的Drawable资源—— ScaleDrawable
- 使用DialogActivity 注意事项
- android自定义静态jar包和动态jar包的编译、使用
- android自定义静态jar包和动态jar包的编译、使用
- android自定义静态jar包和动态jar包的编译、使用
- android自定义静态jar包和动态jar包的编译、使用
- android自定义静态jar包和动态jar包的编译、使用
- Android 关于listview使用总结(不断更新)
- android 手机号码运营商判断
- Android 采用Layout Inflater创建一个View对象
- android studio 错误: 找不到符号 符号: 方法 xxx() 位置: 类 xxx
- Android中如何调用String-array
- Android性能分析工具Traceview的使用
- Android进程间通信之Messenger