Android Corner view implementation and compatibility with different versions

Source: Internet
Author: User
Tags border color

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:

  1. <? XML version="1.0" encoding="Utf-8"?>
  2. < Shape xmlns:android="http://schemas.android.com/apk/res/android" >
  3. < Corners
  4. Android:topleftradius="5DP"
  5. Android:toprightradius="5DP"
  6. Android:bottomleftradius="5DP"
  7. Android:bottomrightradius="5DP"/>
  8. < Stroke
  9. android:width="1DP"
  10. Android:color="#FF5500"
  11. />
  12. </ Shape >


In this,corners refers to the rounded corners, thestroke 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 became a diagonal display, because I did not learn, but in the internet for a long time did not find a solution, back to know the Android loaded Layout file method, you will know this solution, in this record, is to create a file directory called Drawable-v12 under our res, This file directory is the location of the android3.0 version, so just put the correct layout file on it.

The code is as follows:

This is done below the android3.0 (all rounded corners on the left):

  1. <? XML version="1.0" encoding="Utf-8"?>
  2. < Shape xmlns:android="http://schemas.android.com/apk/res/android" >
  3. < Corners
  4. Android:topleftradius="5DP"
  5. Android:bottomrightradius="5DP"/>
  6. < Stroke
  7. android:width="1DP"
  8. Android:color="#FF5500"
  9. />
  10. </ 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:

  1. <? XML version="1.0" encoding="Utf-8"?>
  2. < Shape xmlns:android="http://schemas.android.com/apk/res/android" >
  3. < Corners
  4. Android:topleftradius="5DP"
  5. Android:bottomleftradius="5DP"/>
  6. < Stroke
  7. android:width="1DP"
  8. Android:color="#FF5500"
  9. />
  10. </ Shape >


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

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

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.