在res/drawable目录下穿件shape的xml来实现圆角矩形效果。代码如下:
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <corners android:bottomLeftRadius="8dp" android:bottomRightRadius="8dp" android:topLeftRadius="8dp" android:topRightRadius="8dp" /> <gradient android:angle="45" android:centerColor="#CCFFDD" android:endColor="#CCCCCC" android:startColor="#CCCCCC" /> <padding android:bottom="7dp" android:left="7dp" android:right="7dp" android:top="7dp" /> </shape>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > <Button android:id="@+id/button1" android:layout_width="140dp" android:layout_height="60dp" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:background="@drawable/button" android:text="设置Shape的形状" /> <LinearLayout android:layout_width="200dp" android:layout_height="100dp" android:layout_alignParentLeft="true" android:layout_alignParentRight="true" android:layout_below="@+id/button1" android:layout_marginTop="71dp" <span style="color:#ff0000;"> android:background="@drawable/button"</span> android:orientation="vertical" > </LinearLayout> </RelativeLayout>
原文地址:http://blog.csdn.net/u014600432/article/details/41444827