This article demonstrates how to implement ListView in AndroidRounded cornerEffect.
People like to see some novel view effects on websites and apps. Looking at the right corner, I want to see the rounded corner. In recent years, there has been a burst of rounded corner design wind: The new CSS standard includes the rounded corner elements, especially the rounded corner design is almost everywhere on the iphone, now there are many rounded corner business cards.
Now we will implement a rounded ListView effect. With the design of rounded corners, we do not want to use them everywhere. In android, there are a few interfaces with right angles that are easy to appear sharp, and they are too different from the surrounding interfaces, such as the list of Large columns, setting, and so on. Using the rounded corner will be lively, easy, and better integrated.
Let's take a look at an image that achieves the rounded corner effect on the IPhone:
This effect is everywhere on the Iphone, but it needs to be implemented manually in Android.
Let's take a look at the following example:
Implementation principle:
By judging the position of the items clicked on the ListView, we switch between different selectors. Of course, this switching action needs to be defined in the onInterceptTouchEvent () method of the ListView rewriting.
If (itemnum = 0 ){
If (itemnum = (getAdapter (). getCount ()-1 )){
// Only one
SetSelector (R. drawable. app_list_corner_round );
} Else {
// Item 1
SetSelector (R. drawable. app_list_corner_round_top );
}
} Else if (itemnum = (getAdapter (). getCount ()-1 ))
// Last item
SetSelector (R. drawable. app_list_corner_round_bottom );
Else {
// Intermediate item
SetSelector (R. drawable. app_list_corner_shape );
}
Define Selector
If there is only one item, we need four rounded corners. The app_list_corner_round.xml file is defined as follows:
<? Xml version = "1.0" encoding = "UTF-8"?>
<Shape xmlns: android = "http://schemas.android.com/apk/res/android">
<Gradient android: startColor = "# BFEEFF"
Android: endColor = "# 40B9FF"
Android: angle = "270" type = "parmname" text = "parmname"/>
<Corners android: topLeftRadius = "6dip"
Android: topRightRadius = "6dip"
Android: bottomLeftRadius = "6dip"
Android: bottomRightRadius = "6dip"/>
</Shape>
If it is the first item on the top, the two corners are rounded. The app_list_corner_round_top.xml is defined as follows:
<? Xml version = "1.0" encoding = "UTF-8"?>
<Shape xmlns: android = "http://schemas.android.com/apk/res/android">
<Gradient android: startColor = "# BFEEFF"
Android: endColor = "# 40B9FF"
Android: angle = "270" type = "parmname" text = "parmname"/>
<Corners android: topLeftRadius = "6dip"
Android: topRightRadius = "6dip"/>
</Shape>
If it is the last entry at the bottom, the following two corners are rounded. app_list_corner_round_bottom.xml is defined as follows:
<? Xml version = "1.0" encoding = "UTF-8"?>
<Shape xmlns: android = "http://schemas.android.com/apk/res/android">
<Gradient android: startColor = "# BFEEFF"
Android: endColor = "# 40B9FF"
Android: angle = "270" type = "parmname" text = "parmname"/>
<Corners android: bottomLeftRadius = "6dip"
Android: bottomRightRadius = "6dip"/>
</Shape>
If it is an intermediate item, no rounded corner is required. app_list_corner_shape.xml is defined as follows:
<? Xml version = "1.0" encoding = "UTF-8"?>
<Shape xmlns: android = "http://schemas.android.com/apk/res/android">
<Gradient android: startColor = "# BFEEFF"
Android: endColor = "# 40B9FF"
Android: angle = "270" type = "parmname" text = "parmname"/>
</Shape>
Example: Click to download
Finally, I hope to reprint friends can respect the author's labor results, plus reprint address: http://www.cnblogs.com/hanyonglu/archive/2012/03/18/2404820.html thank you.
Complete. Pai_^