main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent" android:layout_width="fill_parent"
android:orientation="vertical">
<TextView android:layout_width="fill_parent" android:layout_height="500px"
android:text="Hello World!" android:background="@drawable/bg_border
"
android:textColor="#ffffff"/>
</LinearLayout>
drawable文件下建立bg_border.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- 指定圓角矩形的4個圓角的半徑 -->
<corners android:topLeftRadius="20px"
android:topRightRadius="5px"
android:bottomRightRadius="20px"
android:bottomLeftRadius="5px"/>
<!-- 指定邊框線條的寬度和顏色 -->
<stroke android:width="4px" android:color="#f0f" />
<!-- 指定使用漸變背景色,使用sweep類型的漸變
顏色從紅色→綠色→藍色 -->
<gradient android:startColor="#f00"
android:centerColor="#0f0"
android:endColor="#00f"
android:angle="270"
android:centerX="0.5"
android:centerY="0.5"
/>
<!--angle的值:從左到右為0;然后逆時針旋轉,90度為從下到上,270為從上到下。
centerx和centery的值取0-1;表示中間色的位置,中間色分別是0,0.5,1。中間色為0的,則漸變的中間色的位置在最上面;中間色為0.5的,則漸變的中間色在屏幕中間;中間色為1 的,則中間色在屏幕下部。-->
</shape>
運行結果:
<gradient android:startColor="#f00"
android:centerColor="#0f0"
android:endColor="#00f"
android:angle="90"
android:centerX="0.5"
android:centerY="0.5"
/>