50 Android development skills (12 add a rounded border for the Control)

Source: Internet
Author: User

The rounded border of the control can make your App look more beautiful. In fact, it is easy to implement.
(Original address: http://blog.csdn.net/vector_yi/article/details/24463025)
Take a gray Button with a rounded border as an example:


1. Create a ShapeDrawable as the background and create a button_rounded_background.xml file in the drawable directory:

<shape xmlns:android = "http://schemas.android.com/apk/res/android"    android:shape= "rectangle" >    <solid android:color= "#AAAAAA" />    <corners android:radius= "15dp" /></shape>
See the name, in addition to the <solid/>, <corners/> label, <shape/> also supports a lot of different functional labels, for more information, please go to the Android official documentation: http://developer.android.com/guide/topics/resources/drawable-resource.html#Shape
2. Apply ShapeDrawablemain. xml to the Button:
<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>
Now a Button with a rounded border has been built.
ShapeDrawable can be used not only in the Button, but also with all controls with background, such as items in ListView.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.