【Shape】Shape –形状
2016-08-18 18:12
204 查看
1、Shape的初步认识
使用 :android:background=”@drawable/shape”这种形式来添加控件的背景效果
注意:shape只是改变了控件背景的形状而并没有改变控件的形状
要改变控件的形状需要使用自定义控件来重新绘制控件。
虽然不能改变控件的形状,但是在某些情况下还是可以直接应用shape进行操作,例如使用纯色控件(不加载图片)时。
2、Shape的简单使用
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval"> </shape>
通过shape来指定背景的形状
这里可以指定 line(线)、oval(圆)、rectangle(长方形)、ring(圆环)
Shape子项属性介绍:
Corners:背景形状的几个角的弯度
gradient:设置背景形状的颜色 渐变色
solid:设置背景形状的颜色 纯色 – solid和gradient只一个生效
padding:设置间隔
stroke:设置边线颜色
size:形状的大小
3、demo
Xml:<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:id="@+id/iv_circle_header" android:layout_margin="30dp" android:layout_width="200dp" android:text="shape" android:gravity="center" android:textSize="22sp" android:layout_height="200dp" android:background="@drawable/shape_rectangle” </LinearLayout>
Shape_rectangle:
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <corners android:radius="5dp"/> <solid android:color="#00ffff"/> <stroke android:width="1dp" android:color="#8000"/> </shape>
直接可以再xml layout 里面预览到效果
效果图:
相关文章推荐
- flex 控件的重要属性
- 学习Winform文本类控件(Label、Button、TextBox)
- Delphi控件ListView的属性及使用方法详解
- web下载的ActiveX控件自动更新
- WinForm实现按名称递归查找控件的方法
- C#中父窗口和子窗口之间控件互操作实例
- C#编写ActiveX网页截图控件
- Android编程之Button控件用法实例分析
- Android控件之CheckBox、RadioButton用法实例分析
- 在Android开发中使用自定义组合控件的例子
- 一款超酷的Android自定义加载控件
- Android重写View实现全新的控件
- MFC中动态创建控件以及事件响应实现方法
- WinForm自定义函数FindControl实现按名称查找控件
- Android控件之ProgressBar用法实例分析
- WinForm拖拽控件生成副本的解决方法
- ASP.NET动态添加用户控件的方法
- WinForm遍历窗体所有子控件的方法
- ASP.NET的HtmlForm控件学习及Post与Get的区别概述
- 浅析Bootstrap验证控件的使用