Implementation of the Android rounded rectangle

Source: Internet
Author: User

The rounded rectangle effect is achieved by wearing the shape's XML in the Res/drawable directory. The code is as follows:

<?xml version= "1.0" encoding= "Utf-8"? ><shape xmlns:android= "Http://schemas.android.com/apk/res/android"    android:shape= "Rectangle" >    <corners        android:bottomleftradius= "8DP"        android: bottomrightradius= "8DP"        android:topleftradius= "8DP"        android:toprightradius= "8DP"/>    <gradient        android:angle= "android:centercolor="        #CCFFDD "android:endcolor="        #CCCCCC "        android: Startcolor= "#CCCCCC"/>    <padding        android:bottom= "7DP"        android:left= "7DP"        android: right= "7DP"        android:top= "7DP"/></shape>

Layout file:

<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http// Schemas.android.com/tools "android:layout_width=" match_parent "android:layout_height=" Match_parent "Android:paddi ngbottom= "@dimen/activity_vertical_margin" android:paddingleft= "@dimen/activity_horizontal_margin" Android: paddingright= "@dimen/activity_horizontal_margin" android:paddingtop= "@dimen/activity_vertical_margin" tools: Context= ". Mainactivity "> <button android:id=" @+id/button1 "android:layout_width=" 140DP "android:layou t_height= "60DP" android:layout_alignparenttop= "true" android:layout_centerhorizontal= "true" android:b ackground= "@drawable/button" android:text= "set shape"/> <linearlayout android:layout_width= "200DP "Android:layout_height=" 100DP "android:layout_alignparentleft=" true "android:layout_alignparentright  = "true" android:layout_below= "@+id/button1"      android:layout_margintop= "71DP" <span style= "color: #ff0000;" > android:background= "@drawable/button" </span> android:orientation= "vertical" > </linearlayout&gt ;</relativelayout>



Implementation of the Android rounded rectangle

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.