Android開發技巧(為控件添加圓角邊框)
控件的圓角邊框可以使你的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官方文檔:
二、在Button中應用ShapeDrawable
main.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等。
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!