50 Android Development Tips (12 Add a rounded border to a control)

Source: Internet
Author: User

The rounded border of the control makes your app look more beautiful and, in fact, very easy to implement.


(Original address: http://blog.csdn.net/vector_yi/article/details/24463025)

To create a gray button with rounded borders, for example:


First, create a shapedrawable as a background under the Drawable folder to create abutton_rounded_background.xml File:
<shape xmlns:android = "http://schemas.android.com/apk/res/android"    android:shape= "Rectangle" >    < Solid android:color= "#AAAAAA"/>    <corners android:radius= "15DP"/></shape>
In addition to the <solid/>,<corners/> label,,<shape/> also supports a very wide range of functional labels. Many other introductions please visit the official Android Documentation:Http://developer.android.com/guide/topics/resources/drawable-resource.html#Shape
Second, the application of Shapedrawablemain.xml in 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>
at this point, a button with rounded borders has been built.
shapedrawable can be used not only in the button. It can also be applied to all controls with backgrounds, such as item in the ListView.


50 Android Development Tips (12 Add a rounded border to a control)

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.