Java代碼
- <?xml version="1.0" encoding="utf-8"?>
- <shape xmlns:android="http://schemas.android.com/apk/res/android">
- <gradient android:startColor="#c0000000" android:endColor="#c0000000"
- android:angle="90" /><!--背景色彩坡形 -->
- <solid android:color="#00ffffff" /><!-- 背景的填充顏色 -->
- <stroke android:width="3dp" color="#ff000000" /><!-- 描邊,width是邊得寬度,color是顏色 -->
- <corners android:radius="10dp" /><!-- 邊角圓弧的半徑 -->
- <padding
- android:left="3dp"
- android:top="3dp"
- android:right="3dp"
- android:bottom="3dp" /><!-- 四周留出來的空白 -->
- </shape>
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android"> <gradient android:startColor="#c0000000" android:endColor="#c0000000" android:angle="90" /><!--背景色彩坡形 --><solid android:color="#00ffffff" /><!-- 背景的填充顏色 --><stroke android:width="3dp" color="#ff000000" /><!-- 描邊,width是邊得寬度,color是顏色 --><corners android:radius="10dp" /><!-- 邊角圓弧的半徑 --><padding android:left="3dp"android:top="3dp" android:right="3dp"android:bottom="3dp" /><!-- 四周留出來的空白 --></shape>
給不同的view設定shape,可以實現邊白和圓角的效果,類似於系統內建的對話方塊!
就是自訂實現和系統內建相同效果的view。
例如:Java代碼
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical" android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:background="@drawable/rounded_menu_out">
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:background="@drawable/rounded_ignore">
- <GridView android:id="@+id/menu_more_window"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:numColumns="4"
- android:stretchMode="columnWidth"
- android:gravity="center" />
- </LinearLayout>
- </LinearLayout>
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical" android:layout_width="fill_parent"android:layout_height="fill_parent"android:background="@drawable/rounded_menu_out"><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content"android:background="@drawable/rounded_ignore"><GridView android:id="@+id/menu_more_window"android:layout_width="wrap_content"android:layout_height="wrap_content"android:numColumns="4"android:stretchMode="columnWidth"android:gravity="center" /> </LinearLayout></LinearLayout>
其中rounded_menu_out就是外面的邊框,rounded_ignore就是定義裡面的樣式!
跟大家分享一個別人做的例子,聲明:是別人做的,謝謝作者分享!