圆角Listview

放在drawable中
app_list_corner_round.xml       一项时

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <shape xmlns:android="http://schemas.android.com/apk/res/android">  
  3.     <gradient android:startColor="#BFEEFF"   
  4.         android:endColor="#40B9FF"   
  5.         android:angle="270"/>  
  6.     <corners android:topLeftRadius="10dp"  
  7.         android:topRightRadius="10dp"  
  8.         android:bottomLeftRadius="10dp"  
  9.         android:bottomRightRadius="10dp"/>  
  10. </shape>   


app_list_corner_round_top.xml      首项顶端圆角

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <shape xmlns:android="http://schemas.android.com/apk/res/android">  
  3.     <solid android:color="#ffffffff" />  
  4. <gradient android:startColor="#BFEEFF"   
  5.         android:endColor="#40B9FF"   
  6.         android:angle="270"/>  
  7.     <corners android:topLeftRadius="10dp"  
  8.         android:topRightRadius="10dp"/>  
  9. </shape>   


app_list_corner_round_bottom       底部末项圆角

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <shape xmlns:android="http://schemas.android.com/apk/res/android">  
  3.     <gradient android:startColor="#BFEEFF"   
  4.         android:endColor="#40B9FF"   
  5.         android:angle="270"/>  
  6.     <corners android:bottomLeftRadius="10dp"  
  7.         android:bottomRightRadius="10dp" />  
  8. </shape>   

放在src中
CornerListView继承ListView类   

  1. public class CornerListView extends ListView {  
  2.     public CornerListView(Context context) {  
  3.         super(context);  
  4.     }  
  5.   
  6.     public CornerListView(Context context, AttributeSet attrs, int defStyle) {  
  7.         super(context, attrs, defStyle);  
  8.     }  
  9.   
  10.     public CornerListView(Context context, AttributeSet attrs) {  
  11.         super(context, attrs);  
  12.     }  
  13.   
  14.     @Override  
  15.     public boolean onInterceptTouchEvent(MotionEvent ev) {  
  16.         switch (ev.getAction()) {  
  17.         case MotionEvent.ACTION_DOWN:  
  18.                 int x = (int) ev.getX();  
  19.                 int y = (int) ev.getY();  
  20.                 int itemnum = pointToPosition(x, y);  
  21.   
  22.                 if (itemnum == AdapterView.INVALID_POSITION)  
  23.                         break;                   
  24.                 else{  
  25.                     if(itemnum==0){  
  26.                         if(itemnum==(getAdapter().getCount()-1)){                                      
  27.                             setSelector(R.drawable.app_list_corner_round);  
  28.                         }else{  
  29.                             setSelector(R.drawable.app_list_corner_round_top);  
  30.                         }  
  31.                     }else if(itemnum==(getAdapter().getCount()-1))  
  32.                             setSelector(R.drawable.app_list_corner_round_bottom);  
  33.                     else{                              
  34.                         setSelector(R.drawable.app_list_corner_shape);  
  35.                     }  
  36.                 }  
  37.   
  38.                 break;  
  39.         case MotionEvent.ACTION_UP:  
  40.                 break;  
  41.         }  
  42.           
  43.         return super.onInterceptTouchEvent(ev);  
  44.     }  
  45. }  

放在layout中 

  1. <com.*.CornerListView   
  2.     android:id="@+id/listView1"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="wrap_content"  
  5.     android:layout_marginBottom="15dp"  
  6.     android:layout_centerHorizontal="true"  
  7.     android:background="@drawable/shape_bg_listview"   
  8.     android:cacheColorHint="@null"  
  9.     android:layout_marginTop="15dp"  
  10.     android:layout_marginLeft="15dp"  
  11.     android:layout_marginRight="15dp"  
  12.     android:layout_below="@+id/brand_commmon_TextView_2"  
  13.     android:divider="@drawable/linecolor"   
  14.     android:dividerHeight="2.0px"   
  15.     />  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值