zoukankan      html  css  js  c++  java
  • ListView圆角实现

    这里用到了自定义控件,自定义ListView

    package com.example.demo;
    import android.content.Context;
    import android.util.AttributeSet;
    import android.view.MotionEvent;
    import android.widget.AdapterView;
    import android.widget.ListView;
    
    /**
     * 圆角ListView
     */
    public class ListCorn extends ListView {
    
        public ListCorn(Context context) {
            this(context, null);
        }
    
        public ListCorn(Context context, AttributeSet attrs) {
            super(context, attrs);
            //整个listview的圆角背景
            this.setBackgroundResource(R.drawable.corner_list_bg);
        }
    
        @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.corner_list_single_item);
                                    } else {
                                        //第一项
                                        setSelector(R.drawable.corner_list_first_item);
                                    }
                            } else if (itemnum==(getAdapter().getCount()-1)){
                                 //最后一项
                                setSelector(R.drawable.corner_list_last_item);
                            } else {
                                //中间项
                                setSelector(R.drawable.corner_list_item);
                            }
                    }
                    break;
            case MotionEvent.ACTION_UP:
                    break;
            }
            return super.onInterceptTouchEvent(ev);
        }
    }
    

    然后在布局文件中应用

     <com.example.demo.ListCorn
          android:id="@+id/ydlist"
          android:layout_below="@+id/edit"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_alignParentBottom="true"
          android:layout_centerHorizontal="true"
          android:layout_margin="10dp"
           android:cacheColorHint="#00000000"
          android:scrollbars="none" >
      </com.example.demo.ListCorn>
  • 相关阅读:
    网上找的面试题-之一
    python里的Join函数
    【转载51CTO】Linux中引号那些事儿
    【面试编程题】巧妙排序:排序只有1,2,3三个元素的数组,不能统计1,2,3的个数。
    [转载]mininet的安装和使用
    Open vSwitch源码阅读【转】及自己的理解【稍后更新】
    7、8月份安排 进度条
    请不要忽视基础小细节
    【编程之美】2.20 程序理解问题
    GDOI2017爆炸记
  • 原文地址:https://www.cnblogs.com/LIANQQ/p/2938810.html
Copyright © 2011-2022 走看看