shape小例子

布局如下:

activity_main.xml

 1 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 2     xmlns:tools="http://schemas.android.com/tools"
 3     android:layout_width="match_parent"
 4     android:layout_height="match_parent" >
 5 
 6     <TextView
 7         android:layout_width="wrap_content"
 8         android:layout_height="wrap_content"
 9         android:layout_centerInParent="true"
10         android:background="@drawable/border_blue"
11         android:text="@string/hello_world" />
12 
13 </RelativeLayout>
activity_main.xml

shape

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >
<stroke android:width="1dip" android:color="#ff001CC9" /> <solid android:color="#ffffffff" /> <gradient android:angle="270" android:endColor="#ffffff" android:startColor="#000000" /> <corners android:radius="3.0dip" /> <padding android:bottom="2.0dip" android:left="3.0dip" android:right="3.0dip" android:top="2.0dip" /> </shape>

实现效果:

android:shape有四种形状,分别为:
rectangle矩形 oval椭圆形 line线形 ring环形。
stroke属性表示描边即外框,可以设置边框的颜色和宽度。
solid属性表示形状内的填充,可以设置填充色。
gradient属性表示形状内的渐变色,可以设置初始夜色和最终颜色。
android:angle="270"表示渐变角度,必须为45的整数倍,常用的0为从左到右渐变,90为从下到上渐变,相对应的180就是从右到左渐变,270为从上到下渐变,从0到360(0)逆时针变化。
corners属性表示圆角的弧度,即本例中矩形四个角的弧度,也可以单独设置各个角的弧度。如:android:topLeftRadius属性。
padding属性即各个方向的填充。








原文地址:https://www.cnblogs.com/silenceshining/p/4689994.html