
在Iphone中这种效果处处可见,但在Android中就需要我们手动实现了。
我们先看下示例运行效果图,如下所示:


实现原理:
通过判断ListView上点击的项的位置,我们切换不同的选择器,当然这个切换的动作我们需要定义在重写ListView的
onInterceptTouchEvent()方法中。 if(itemnum==0){ if(itemnum==(getAdapter().getCount()-1)){ //只有一项 setSelector(R.drawable.app_list_corner_round); }else{ //第一项 setSelector(R.drawable.app_list_corner_round_top); }}else if(itemnum==(getAdapter().getCount()-1)) //最后一项 setSelector(R.drawable.app_list_corner_round_bottom);else{ //中间一项 setSelector(R.drawable.app_list_corner_shape);}定义选择器: <?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>如果是顶部第一项,则上面两个角为圆角,app_list_corner_round_top.xml定义如下:
<?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>如果是底部最后一项,则下面两个角为圆角,app_list_corner_round_bottom.xml定义如下:
<?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" /></shape>如果是中间项,则应该不需要圆角, app_list_corner_shape.xml定义如下:
<?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"/></shape>原文地址:http://www.cnblogs.com/hanyonglu/archive/2012/03/18/2404820.html