我写这篇文章受到了kiritor的专栏发表的博文Android UI控件之ListView实现圆角效果的启发。

先看效果图:


首先,你得写一个类我们命名为CornerListView

/** * 圆角ListView示例 * @Description: 圆角ListView示例 * @FileName: CornerListView.java  */public class CornerListView extends ListView {    public CornerListView(Context context) {        super(context);    }    public CornerListView(Context context, AttributeSet attrs, int defStyle) {        super(context, attrs, defStyle);    }    public CornerListView(Context context, AttributeSet attrs) {        super(context, attrs);    }    @Override    public boolean onInterceptTouchEvent(MotionEvent ev) {        switch (ev.getAction()) {        case MotionEvent.ACTION_DOWN:                int x = (int) ev.getX();                int y = (int) ev.getY();                int itemnum = pointToPosition(x, y);                if (itemnum == AdapterView.INVALID_POSITION)                        break;                                 else{                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);                }                }                break;        case MotionEvent.ACTION_UP:                break;        }                return super.onInterceptTouchEvent(ev);    }}

其中,app_list_corner_round

<?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 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 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 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> 

写好了之后,就可以在你的代码中直接像listview一样调用。

安卓市场:http://apk.hiapk.com/html/2013/05/1468059.html?module=256&info=IWjtVg9cqVJLYg%3D%3D
N多市场:http://www.nduoa.com/apk/detail/553415

360手机助手:http://zhushou.360.cn/search/index/?kw=%E6%A0%A1%E5%9B%AD%E5%B0%8F%E5%8A%A9%E6%89%8B

百度应用:http://as.baidu.com/a/item?docid=3101724&pre=web_am_se

优亿市场(eoe):http://www.eoemarket.com/search/apps/?keyword=%E6%A0%A1%E5%9B%AD%E5%B0%8F%E5%8A%A9%E6%89%8B


更多相关文章

  1. Android(安卓)ListView下拉刷新上拉自动加载更多DEMO示例
  2. 移动接口开发:JAVA判断是android还是ios 端请求
  3. Android(安卓)HTTP 服务
  4. android检测网络连接状态示例讲解
  5. Android设备双屏异显
  6. 个人知识体系(持续更新)
  7. Android网络数据开关用法简单示例
  8. Android(安卓)ApiDemos示例解析(39):App->Service->Local Service
  9. Android中Shared Preferences、Files、Network、SQLite数据库编

随机推荐

  1. 异常 报错 Android library projects can
  2. Android AsyncTask问题
  3. android MotionEvent详解
  4. Android布局居中的几种做法
  5. Kotlin编程之AndroidStudio(包括3.0与2.x
  6. Eclipse中安装Android并配置IDE(集成开发
  7. Android中的接口回调
  8. Android 中文API (65) —— BluetoothClass
  9. Android:Activity(七):Fragment与Activit
  10. Android(安卓)- Binder驱动