50個Android開發技巧(12 為控制項添加圓角邊框)

來源:互聯網
上載者:User

控制項的圓角邊框可以使你的App看起來更美觀,其實實現起來也很簡單。
(原文地址:http://blog.csdn.net/vector_yi/article/details/24463025)
以建立一個灰色的帶圓角邊框的Button為例:


一、建立一個ShapeDrawable作為背景在drawable目錄下建立一個button_rounded_background.xml檔案:

<shape xmlns:android = "http://schemas.android.com/apk/res/android"    android:shape= "rectangle" >    <solid android:color= "#AAAAAA" />    <corners android:radius= "15dp" /></shape>
見名知意,除了<solid/>,<corners/>標籤外,<shape/>還支援很多不同功能標籤,更多介紹請移步Android官方文檔:http://developer.android.com/guide/topics/resources/drawable-resource.html#Shape
二、在Button中應用ShapeDrawablemain.xml:
<RelativeLayout xmlns:android = "http://schemas.android.com/apk/res/android"    android:layout_width= "fill_parent"    android:layout_height= "fill_parent"    android:gravity= "center" >    <Button        android:id ="@+id/button"        android:layout_width ="wrap_content"        android:layout_height ="wrap_content"        android:background ="@drawable/button_rounded_background"        android:padding ="10dp"        android:text ="@string/hello"        android:textColor ="#000000" /></RelativeLayout>
至此就已經構建完成了一個帶圓角邊框的Button。
ShapeDrawable不僅可以利用在Button中,它還可以應用與所有帶背景的控制項,例如ListView中的Item等。


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.