Android How to set the rounded rectangle background of a control

Source: Internet
Author: User

When we need to implement a rounded rectangle for the control or to add a border to the background, the best way to do this is not to create a background image or add ImageView as a boundary, but to use shape.

The idea is to customize a landscaping layout in the Drawable folder, the code is as follows

<?xml version= "1.0" encoding= "Utf-8"? ><shape xmlns:android= "Http://schemas.android.com/apk/res/android" >    <solid android:color= "#F5F5F5"/>    <stroke            android:width= "2DP"            android:color= "# Dcd8d8 "/>    <corners android:topleftradius=" 5DP "             android:toprightradius=" 5DP "             android: bottomrightradius= "5DP"             android:bottomleftradius= "5DP"/></shape>


Where the <stroke> tag is set the border color and width of the,<corners> can set the fillet and its radius. During the test, Android does not support the four-corner radius inconsistency.

Android How to set the rounded rectangle background of 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.