放在drawable中
app_list_corner_round.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="10dp"
- android:topRightRadius="10dp"
- android:bottomLeftRadius="10dp"
- android:bottomRightRadius="10dp"/>
- </shape>
app_list_corner_round_top.xml 首项顶端圆角
- <?xml version="1.0" encoding="utf-8"?>
- <shape xmlns:android="http://schemas.android.com/apk/res/android">
- <solid android:color="#ffffffff" />
- <gradient android:startColor="#BFEEFF"
- android:endColor="#40B9FF"
- android:angle="270"/>
- <corners android:topLeftRadius="10dp"
- android:topRightRadius="10dp"/>
- </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="10dp"
- android:bottomRightRadius="10dp" />
- </shape>
放在src中
CornerListView继承ListView类
- 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);
- }
- }
放在layout中
- <com.*.CornerListView
- android:id="@+id/listView1"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_marginBottom="15dp"
- android:layout_centerHorizontal="true"
- android:background="@drawable/shape_bg_listview"
- android:cacheColorHint="@null"
- android:layout_marginTop="15dp"
- android:layout_marginLeft="15dp"
- android:layout_marginRight="15dp"
- android:layout_below="@+id/brand_commmon_TextView_2"
- android:divider="@drawable/linecolor"
- android:dividerHeight="2.0px"
- />