This article demonstrates how to implement a ListView fillet effect in Android .
Whether it's a website or an app, people love to see some new view effects. Right angle see much, want to look at rounded corner, in the past few years blew the round angle design Wind: The new CSS standard into rounded elements, especially in the iphone almost everywhere round corner design, now also began to appear many round corner business card.
Now we can achieve a rounded corner listview effect. Rounded corners of the design, we do not seek to use everywhere, everywhere, Android has a few interfaces with right angle is really easy to appear sharp, and the peripheral interface is too contrast and appear uncoordinated, such as large column list, settings and so on, and the use of rounded corners to achieve, it will be lively, more relaxed, but also the integration of particularly good.
Take a look at a picture of the fillet effect in the iphone:
This effect is visible everywhere in the iphone, but it's needed to be implemented manually on Android.
Let's take a look at the sample run effect diagram, as follows:
Implementation principle:
By judging the position of the item clicked on the ListView, we switch the different selectors, of course this toggle action we need to define in the rewrite listview
Onintercepttouchevent () method.
if (itemnum==0) {
if (itemnum== (Getadapter (). GetCount ()-1)) {
//Only one
setselector (r.drawable.app_ List_corner_round);
} else{
//First
setselector (r.drawable.app_list_corner_round_top);
}
else if (itemnum== (Getadapter (). GetCount ()-1))
//Last
Setselector (r.drawable.app_list_corner_round_ bottom);
else{
//Middle one
setselector (r.drawable.app_list_corner_shape);
}
Define selector:
If there is only one, we need four corners to be rounded, 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"/>
<corners android:topleftradius= "6dip"
android:toprightradius= "6dip"
android: bottomleftradius= "6dip"
android:bottomrightradius= "6dip"/>
</shape>
If it is the first item at the top, the top two corners are rounded, and 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 "/>
<corners android:topleftradius=" 6dip "
android:toprightradius=" 6dip "/>
</shape >
If this is the last item at the bottom, the following two corners are rounded, and 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"/>
<corners android:bottomleftradius= "6dip"
android:bottomrightradius= "6dip"/>
If it is an intermediate item, you should not need rounded corners, 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 "/>
Original address: http://www.cnblogs.com/hanyonglu/archive/2012/03/18/2404820.html
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.