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 里面预览到效果
效果图: