Android fillet view implementation and compatibility with different versions (android3.0 later)

Source: Internet
Author: User
Tags border color

http://blog.csdn.net/lovecluo/article/details/8710174

In our own app, in order to make the app look better, we need to turn our own view into rounded corners, after all, the mainstream is also a lot of things to make rounded corners, and the appearance of Apple looks similar, looks good.
It's also easy to make a view rounded, just build a custom drawable.
We set up a shape drawable below res/drawable, with the following code:

<?XML version= "1.0" encoding= "Utf-8"?><Shapexmlns:android= "Http://schemas.android.com/apk/res/android" >    <CornersAndroid:topleftradius= "5DP"Android:toprightradius= "5DP"Android:bottomleftradius= "5DP"Android:bottomrightradius= "5DP"/>    <StrokeAndroid:width= "1DP"Android:color= "#FF5500"        /></Shape>

In this, corners refers to the rounded corners, the stroke refers to the border color, related information about shape can look at the official documents, or search online, there is a very detailed blog.

There was no problem, but I was in the back to do that only the left has rounded corners and only the right side has a fillet, there is a problem, that is, before android3.0, Android:bottomleftradius and Android: Bottomrightradius is the opposite, that is, I was just set to the left, but a diagonal display, because I did not learn, but in the internet for a long time did not find a solution, after knowing the Android loading layout file method, we know this solution , in this record, is in our res set up a directory called DRAWABLE-V12, this file directory is the location of the android3.0 after the version access, so only need to put the correct layout file inside this can be.
The code is as follows:
This is done below the android3.0 (all rounded corners on the left):

<?XML version= "1.0" encoding= "Utf-8"?><Shapexmlns:android= "Http://schemas.android.com/apk/res/android" >    <CornersAndroid:topleftradius= "5DP"Android:bottomrightradius= "5DP"/>    <StrokeAndroid:width= "1DP"Android:color= "#FF5500"        /></Shape>

And in android3.0 above version, Google solves this problem for us, so we just need to follow the normal situation of writing, and put the file under the RES/DRAWABLE-V12, as follows:

<?XML version= "1.0" encoding= "Utf-8"?><Shapexmlns:android= "Http://schemas.android.com/apk/res/android" >    <CornersAndroid:topleftradius= "5DP"Android:bottomleftradius= "5DP"/>    <StrokeAndroid:width= "1DP"Android:color= "#FF5500"        /></Shape>

On the right and above the solution is consistent, here will not repeat.

My source Address: http://download.csdn.net/detail/lovecluo/5173334

Android fillet view implementation and compatibility with different versions (android3.0 later)

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.