android shape的用法總結

來源:互聯網
上載者:User
Java代碼

  1. <?xml version="1.0" encoding="utf-8"?> 
  2. <shape xmlns:android="http://schemas.android.com/apk/res/android"> 
  3.     <gradient android:startColor="#c0000000"  android:endColor="#c0000000" 
  4.                 android:angle="90" /><!--背景色彩坡形 --> 
  5.     <solid android:color="#00ffffff" /><!-- 背景的填充顏色 --> 
  6.     <stroke android:width="3dp" color="#ff000000" /><!-- 描邊,width是邊得寬度,color是顏色 --> 
  7.     <corners android:radius="10dp" /><!-- 邊角圓弧的半徑 --> 
  8.     <padding  
  9.         android:left="3dp" 
  10.         android:top="3dp"  
  11.         android:right="3dp" 
  12.         android:bottom="3dp" /><!-- 四周留出來的空白 --> 
  13. </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代碼

  1. <?xml version="1.0" encoding="utf-8"?> 
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
  3.     android:orientation="vertical" android:layout_width="fill_parent" 
  4.     android:layout_height="fill_parent" 
  5.     android:background="@drawable/rounded_menu_out"> 
  6. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
  7.     android:orientation="vertical" 
  8.     android:layout_width="wrap_content" 
  9.     android:layout_height="wrap_content" 
  10.     android:background="@drawable/rounded_ignore"> 
  11.     <GridView android:id="@+id/menu_more_window" 
  12.         android:layout_width="wrap_content" 
  13.         android:layout_height="wrap_content" 
  14.         android:numColumns="4" 
  15.         android:stretchMode="columnWidth" 
  16.         android:gravity="center" />     
  17. </LinearLayout> 
  18. </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就是定義裡面的樣式!
跟大家分享一個別人做的例子,聲明:是別人做的,謝謝作者分享!

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.