【android】shape的使用
2014-01-06 11:08
106 查看
例子:XML 文件保存在
下面这个 XML 把shape应用到view:
在程序代码里获取shape,应用到view
例子
res/drawable/gradient_box.xml:
<?xml version="1.0" encoding="utf-8"?> <shapexmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <gradient android:startColor="#FFFF0000" android:endColor="#80FF00FF" android:angle="45"/> <paddingandroid:left="7dp" android:top="7dp" android:right="7dp" android:bottom="7dp"/> <cornersandroid:radius="8dp"/> </shape>
下面这个 XML 把shape应用到view:
<TextView android:background="@drawable/gradient_box" android:layout_height="wrap_content" android:layout_width="wrap_content"/>
在程序代码里获取shape,应用到view
Resources res =getResources(); Drawable shape = res.getDrawable(R.drawable.gradient_box); TextView tv =(TextView)findViewByID(R.id.textview); tv.setBackground(shape);
例子
<?xml version="1.0" encoding="utf-8"?> <shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android"> <!-- 渐变 --> <!-- 详细内容 http://developer.android.com/guide/topics/resources/drawable-resource.html#Shape --> <gradient android:startColor="#0000ff" android:endColor="#00bfff" android:angle="45" android:centerX="0.5"/> <!-- 圆角 --> <corners android:radius="8dp"/> <!-- 外边间距 --> <padding android:left="7dp" android:top="7dp" android:right="7dp" android:bottom="7dp" /> <!-- 描边 --> <stroke android:width="2dp" android:color="#dcdcdc" android:dashWidth="5dp" android:dashGap="0dp" /> <!-- dashgap 表示间隔 有了间隔就成了虚线 --> </shape>
相关文章推荐
- Android中shape的使用
- Android中shape的使用
- android:shape的使用
- Android中Shape、selector在xml中的使用、切换按钮的背景图案
- android shape的使用
- Android使用Shape实现ProgressBar样式实例
- android 使用shape来优化界面效果
- 【android】shape的使用
- android shape的使用
- android shape的使用
- Android笔记----Shape标签使用
- Android中的Shape和Selector的结合使用实例
- android shape的使用详解以及常用效果(渐变色、分割线、边框、半透明阴影效果等)
- Android:shape的使用详解(1)
- android:shape的使用
- Android的shape和颜色选择器结合使用
- android shape的使用
- android shape的使用
- android studio shape使用