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