Android rounded corner View implementation and compatibility with different versions, android rounded corner

Source: Internet
Author: User

Android rounded corner View implementation and compatibility with different versions, android rounded corner

When creating our own apps, we need to make our own views rounded to make the apps look better. After all, the mainstream also makes many things rounded, it looks similar to Apple and looks good.

It is easy to make a View into a rounded corner. You only need to create a custom Drawable.

We create a shape drawable under res/drawable. The Code is as follows:


[Html]View plaincopy
  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 example, corners refers to the rounded corner and stroke refers to the border color. For details about the shape, refer to the official documentation or search for it online.

There was no problem, but I was working on the problem that there were only rounded corners on the left and only rounded corners on the right, that is, before android3.0, android: bottomLeftRadius and android: bottomRightRadius is the opposite. That is to say, I set it to the left, but it becomes a diagonal display. Because I have not learned it well, I have not found a solution for a long time on the Internet, after knowing the android loading layout file method, you will know the solution, this is recorded here, is to create a file directory named drawable-v12 under our res, this file directory is accessed by Versions later than android3.0, so you only need to place the correct layout file in it.

The Code is as follows:

Write the following in android3.0 (rounded corners on the left ):


[Html]View plaincopy
  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>

In versions above android3.0, google solves this problem for us, so we only need to write according to the normal situation, and put the file under res/drawable-v12 on the line, as shown below:


 

[Html]View plaincopy
  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>

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.