控件 -- ListView

一、概念

列表展示控件。

二、基本使用

//fruit_item.xml


    
    


//header_item.xml


    


//footer_item.xml





//ViewHolderAdapter
public class ViewHolderAdapter extends BaseAdapter {
    private static final String TAG = "ViewHolderAdapter";
    private List mData;
    private LayoutInflater mInflater;

    public ViewHolderAdapter(Context context, List data) {
        mData = data;
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        int count = mData.size();
        //Log.d(TAG, "zwm, count: " + count);
        return count;
    }

    @Override
    public Object getItem(int position) {
        Object item = mData.get(position);
        //Log.d(TAG, "zwm, item: " + item);
        return item;
    }

    @Override
    public long getItemId(int position) {
        //Log.d(TAG, "zwm, getItemId: " + position);
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Log.d(TAG, "zwm, getView: " + position);
        ViewHolder viewHolder;
        // 判断是否缓存
        if (convertView == null) {
            viewHolder = new ViewHolder();
            // 通过LayoutInflater实例化布局
            convertView = mInflater.inflate(R.layout.fruit_item, null);
            viewHolder.img = convertView.findViewById(R.id.fruit_image);
            viewHolder.title = convertView.findViewById(R.id.fruit_name);
            convertView.setTag(viewHolder);
        } else {
            // 通过tag找到缓存的布局,复用convertView并使用ViewHolder
            viewHolder = (ViewHolder) convertView.getTag();
        }
        // 设置布局中控件要显示的视图
        viewHolder.img.setImageResource(R.drawable.ic_launcher);
        viewHolder.title.setText(mData.get(position).getName());
        return convertView;
    }

    private static class ViewHolder {
        ImageView img;
        TextView title;
    }
}

//activity_main.xml


    

    


//MainActivity
public class MainActivity extends AppCompatActivity {
    private static final String TAG = "MainActivity";
    private ListView listView;
    private ViewHolderAdapter adapter;
    private List fruitList = new ArrayList<>();
    private int lastVisibleItem = 0;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Log.d(TAG, "zwm, onCreate");
        initFruits();
        listView = findViewById(R.id.list_view);
        View headerView = LayoutInflater.from(this).inflate(R.layout.header_item, null);
        View footerView = LayoutInflater.from(this).inflate(R.layout.footer_item, null);
        listView.addHeaderView(headerView); //添加头视图
        listView.addFooterView(footerView); //添加尾视图
        listView.setEmptyView(findViewById(R.id.empty_view)); //设置EmptyView
        adapter = new ViewHolderAdapter(this, fruitList);
        listView.setAdapter(adapter);
        listView.setOnTouchListener(new View.OnTouchListener() { //设置触摸监听
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                switch (event.getAction()) {
                    case MotionEvent.ACTION_DOWN:
                        // 触摸时操作
                        Log.d(TAG, "zwm, MotionEvent.ACTION_DOWN");
                        break;
                    case MotionEvent.ACTION_MOVE:
                        // 移动时操作
                        Log.d(TAG, "zwm, MotionEvent.ACTION_MOVE");
                        break;
                    case MotionEvent.ACTION_UP:
                        // 离开时操作
                        Log.d(TAG, "zwm, MotionEvent.ACTION_UP");
                        break;
                }
                return false;
            }
        });
        listView.setOnScrollListener(new AbsListView.OnScrollListener() { //设置滚动监听
            @Override
            public void onScrollStateChanged(AbsListView view, int scrollState) {
                switch (scrollState) {
                    case SCROLL_STATE_IDLE:
                        // 滑动停止时
                        Log.d(TAG, "zwm, SCROLL_STATE_IDLE");
                        break;
                    case SCROLL_STATE_TOUCH_SCROLL:
                        // 正在滚动
                        Log.d(TAG, "zwm, SCROLL_STATE_TOUCH_SCROLL");
                        break;
                    case SCROLL_STATE_FLING:
                        // 手指抛动时,即手指用力滑动
                        // 在离开后ListView由于惯性继续滑动
                        Log.d(TAG, "zwm, SCROLL_STATE_FLING");
                        break;
                }
            }

            //firstVisibleItem:当前能看见的第一个Item的ID(从0开始)
            //visibleItemCount:当前能看见的Item的总数
            //totalItemCount:整个ListView的Item总数
            @Override
            public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
                // 滚动时一直调用
                Log.d(TAG, "zwm, onScroll, firstVisibleItem: " + firstVisibleItem + ", visibleItemCount: " + visibleItemCount + ", totalItemCount: " + totalItemCount);
                Log.d(TAG, "zwm, lastVisibleItem: " + lastVisibleItem);
                //判断滚动的方向
                if(firstVisibleItem > lastVisibleItem){
                    Log.d(TAG, "zwm, 上滑");
                } else if (firstVisibleItem < lastVisibleItem){
                    Log.d(TAG, "zwm, 下滑");
                }
                lastVisibleItem = firstVisibleItem;

                //判断是否滚动到最后一行
                if (firstVisibleItem + visibleItemCount == totalItemCount && totalItemCount > 0) {
                    Log.d(TAG, "zwm, 滚动到最后一行");
                }
            }
        });

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                Log.d(TAG, "zwm, test add fruit");
                Fruit fruit = new Fruit("add fruit", R.drawable.ic_launcher);
                fruitList.add(fruit);
                adapter.notifyDataSetChanged();

                // 获取可视区域内第一个Item的id
                Log.d(TAG, "zwm, getFirstVisiblePosition: " + listView.getFirstVisiblePosition());
                // 获取可视区域内最后一个Item的id
                Log.d(TAG, "zwm, getLastVisiblePosition: " + listView.getLastVisiblePosition());
            }
        }, 5000);
    }

    private void initFruits() {
        Fruit fruit = new Fruit("苹果", R.drawable.ic_launcher);
        fruitList.add(fruit);
        fruit = new Fruit("香蕉", R.drawable.ic_launcher);
        fruitList.add(fruit);
        fruit = new Fruit("西瓜", R.drawable.ic_launcher);
        fruitList.add(fruit);
        fruit = new Fruit("龙眼", R.drawable.ic_launcher);
        fruitList.add(fruit);
        fruit = new Fruit("荔枝", R.drawable.ic_launcher);
        fruitList.add(fruit);
        fruit = new Fruit("樱桃", R.drawable.ic_launcher);
        fruitList.add(fruit);
        fruit = new Fruit("核桃", R.drawable.ic_launcher);
        fruitList.add(fruit);
        fruit = new Fruit("橙子", R.drawable.ic_launcher);
        fruitList.add(fruit);
    }
}

//输出log
2020-01-21 09:18:44.065 32227-32227/com.example.sourcecodetest D/MyApplication: zwm, onCreate
2020-01-21 09:18:44.350 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, onCreate
2020-01-21 09:18:44.364 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, onScroll, firstVisibleItem: 0, visibleItemCount: 0, totalItemCount: 10
2020-01-21 09:18:44.364 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, lastVisibleItem: 0
2020-01-21 09:18:44.573 32227-32227/com.example.sourcecodetest D/ViewHolderAdapter: zwm, getView: 0
2020-01-21 09:18:44.584 32227-32227/com.example.sourcecodetest D/ViewHolderAdapter: zwm, getView: 1
2020-01-21 09:18:44.592 32227-32227/com.example.sourcecodetest D/ViewHolderAdapter: zwm, getView: 2
2020-01-21 09:18:44.598 32227-32227/com.example.sourcecodetest D/ViewHolderAdapter: zwm, getView: 3
2020-01-21 09:18:44.606 32227-32227/com.example.sourcecodetest D/ViewHolderAdapter: zwm, getView: 4
2020-01-21 09:18:44.613 32227-32227/com.example.sourcecodetest D/ViewHolderAdapter: zwm, getView: 5
2020-01-21 09:18:44.621 32227-32227/com.example.sourcecodetest D/ViewHolderAdapter: zwm, getView: 6
2020-01-21 09:18:44.628 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, onScroll, firstVisibleItem: 0, visibleItemCount: 8, totalItemCount: 10
2020-01-21 09:18:44.628 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, lastVisibleItem: 0
2020-01-21 09:18:47.932 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_DOWN
2020-01-21 09:18:47.945 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:18:48.004 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:18:48.011 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, SCROLL_STATE_TOUCH_SCROLL
2020-01-21 09:18:48.012 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, onScroll, firstVisibleItem: 0, visibleItemCount: 8, totalItemCount: 10
2020-01-21 09:18:48.012 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, lastVisibleItem: 0
2020-01-21 09:18:48.019 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:18:48.019 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, onScroll, firstVisibleItem: 1, visibleItemCount: 7, totalItemCount: 10
2020-01-21 09:18:48.019 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, lastVisibleItem: 0
2020-01-21 09:18:48.019 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, 上滑
2020-01-21 09:18:48.035 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:18:48.036 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, onScroll, firstVisibleItem: 1, visibleItemCount: 7, totalItemCount: 10
2020-01-21 09:18:48.036 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, lastVisibleItem: 1
2020-01-21 09:18:48.053 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:18:48.054 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, onScroll, firstVisibleItem: 1, visibleItemCount: 7, totalItemCount: 10
2020-01-21 09:18:48.054 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, lastVisibleItem: 1
2020-01-21 09:18:48.070 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:18:48.071 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, onScroll, firstVisibleItem: 1, visibleItemCount: 7, totalItemCount: 10
2020-01-21 09:18:48.071 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, lastVisibleItem: 1
2020-01-21 09:18:48.086 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:18:48.087 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, onScroll, firstVisibleItem: 1, visibleItemCount: 7, totalItemCount: 10
2020-01-21 09:18:48.087 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, lastVisibleItem: 1
2020-01-21 09:18:48.103 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:18:48.104 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, onScroll, firstVisibleItem: 1, visibleItemCount: 7, totalItemCount: 10
2020-01-21 09:18:48.104 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, lastVisibleItem: 1
2020-01-21 09:18:48.119 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:18:48.120 32227-32227/com.example.sourcecodetest D/ViewHolderAdapter: zwm, getView: 7
2020-01-21 09:18:48.124 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, onScroll, firstVisibleItem: 2, visibleItemCount: 7, totalItemCount: 10
2020-01-21 09:18:48.125 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, lastVisibleItem: 1
2020-01-21 09:18:48.125 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, 上滑
2020-01-21 09:18:48.131 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:18:48.132 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, onScroll, firstVisibleItem: 2, visibleItemCount: 7, totalItemCount: 10
2020-01-21 09:18:48.132 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, lastVisibleItem: 2
2020-01-21 09:18:48.135 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_UP
2020-01-21 09:18:48.136 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, SCROLL_STATE_FLING
2020-01-21 09:18:48.140 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, onScroll, firstVisibleItem: 2, visibleItemCount: 7, totalItemCount: 10
2020-01-21 09:18:48.140 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, lastVisibleItem: 2
2020-01-21 09:18:48.152 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, onScroll, firstVisibleItem: 2, visibleItemCount: 7, totalItemCount: 10
2020-01-21 09:18:48.152 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, lastVisibleItem: 2
2020-01-21 09:18:48.169 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, onScroll, firstVisibleItem: 2, visibleItemCount: 7, totalItemCount: 10
2020-01-21 09:18:48.169 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, lastVisibleItem: 2
2020-01-21 09:18:48.186 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, onScroll, firstVisibleItem: 2, visibleItemCount: 7, totalItemCount: 10
2020-01-21 09:18:48.186 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, lastVisibleItem: 2
2020-01-21 09:18:48.206 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, onScroll, firstVisibleItem: 2, visibleItemCount: 8, totalItemCount: 10
2020-01-21 09:18:48.206 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, lastVisibleItem: 2
2020-01-21 09:18:48.206 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, 滚动到最后一行
2020-01-21 09:18:48.220 32227-32227/com.example.sourcecodetest D/ViewHolderAdapter: zwm, getView: 1
2020-01-21 09:18:48.223 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, onScroll, firstVisibleItem: 2, visibleItemCount: 8, totalItemCount: 10
2020-01-21 09:18:48.224 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, lastVisibleItem: 2
2020-01-21 09:18:48.224 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, 滚动到最后一行
2020-01-21 09:18:48.406 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, SCROLL_STATE_IDLE
2020-01-21 09:18:49.366 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, test add fruit
2020-01-21 09:18:49.368 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, getFirstVisiblePosition: 2
2020-01-21 09:18:49.369 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, getLastVisiblePosition: 9
2020-01-21 09:18:49.394 32227-32227/com.example.sourcecodetest D/ViewHolderAdapter: zwm, getView: 1
2020-01-21 09:18:49.401 32227-32227/com.example.sourcecodetest D/ViewHolderAdapter: zwm, getView: 2
2020-01-21 09:18:49.405 32227-32227/com.example.sourcecodetest D/ViewHolderAdapter: zwm, getView: 3
2020-01-21 09:18:49.409 32227-32227/com.example.sourcecodetest D/ViewHolderAdapter: zwm, getView: 4
2020-01-21 09:18:49.413 32227-32227/com.example.sourcecodetest D/ViewHolderAdapter: zwm, getView: 5
2020-01-21 09:18:49.416 32227-32227/com.example.sourcecodetest D/ViewHolderAdapter: zwm, getView: 6
2020-01-21 09:18:49.420 32227-32227/com.example.sourcecodetest D/ViewHolderAdapter: zwm, getView: 7
2020-01-21 09:18:49.428 32227-32227/com.example.sourcecodetest D/ViewHolderAdapter: zwm, getView: 8
2020-01-21 09:18:49.441 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, onScroll, firstVisibleItem: 2, visibleItemCount: 8, totalItemCount: 11
2020-01-21 09:18:49.441 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, lastVisibleItem: 2
2020-01-21 09:18:51.153 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_DOWN
2020-01-21 09:18:51.159 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:18:51.177 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:18:51.193 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:18:51.260 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:18:51.268 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, onScroll, firstVisibleItem: 2, visibleItemCount: 8, totalItemCount: 11
2020-01-21 09:18:51.268 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, lastVisibleItem: 2
2020-01-21 09:18:51.276 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:18:51.295 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:18:51.300 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, SCROLL_STATE_TOUCH_SCROLL
2020-01-21 09:18:51.301 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, onScroll, firstVisibleItem: 2, visibleItemCount: 8, totalItemCount: 11
2020-01-21 09:18:51.301 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, lastVisibleItem: 2
2020-01-21 09:18:51.310 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:18:51.312 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, onScroll, firstVisibleItem: 3, visibleItemCount: 7, totalItemCount: 11
2020-01-21 09:18:51.312 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, lastVisibleItem: 2
2020-01-21 09:18:51.312 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, 上滑
2020-01-21 09:18:51.330 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:18:51.331 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, onScroll, firstVisibleItem: 3, visibleItemCount: 7, totalItemCount: 11
2020-01-21 09:18:51.332 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, lastVisibleItem: 3
2020-01-21 09:18:51.343 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:18:51.344 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, onScroll, firstVisibleItem: 3, visibleItemCount: 7, totalItemCount: 11
2020-01-21 09:18:51.345 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, lastVisibleItem: 3
2020-01-21 09:18:51.361 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:18:51.363 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, onScroll, firstVisibleItem: 3, visibleItemCount: 7, totalItemCount: 11
2020-01-21 09:18:51.363 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, lastVisibleItem: 3
2020-01-21 09:18:51.377 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:18:51.378 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, onScroll, firstVisibleItem: 3, visibleItemCount: 7, totalItemCount: 11
2020-01-21 09:18:51.379 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, lastVisibleItem: 3
2020-01-21 09:18:51.394 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:18:51.395 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, onScroll, firstVisibleItem: 3, visibleItemCount: 7, totalItemCount: 11
2020-01-21 09:18:51.395 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, lastVisibleItem: 3
2020-01-21 09:18:51.412 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:18:51.413 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, onScroll, firstVisibleItem: 3, visibleItemCount: 7, totalItemCount: 11
2020-01-21 09:18:51.413 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, lastVisibleItem: 3
2020-01-21 09:18:51.426 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:18:51.427 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, onScroll, firstVisibleItem: 3, visibleItemCount: 7, totalItemCount: 11
2020-01-21 09:18:51.427 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, lastVisibleItem: 3
2020-01-21 09:18:51.442 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:18:51.443 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, onScroll, firstVisibleItem: 3, visibleItemCount: 7, totalItemCount: 11
2020-01-21 09:18:51.443 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, lastVisibleItem: 3
2020-01-21 09:18:51.459 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:18:51.461 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, onScroll, firstVisibleItem: 3, visibleItemCount: 8, totalItemCount: 11
2020-01-21 09:18:51.461 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, lastVisibleItem: 3
2020-01-21 09:18:51.461 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, 滚动到最后一行
2020-01-21 09:18:51.477 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:18:51.478 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, onScroll, firstVisibleItem: 3, visibleItemCount: 8, totalItemCount: 11
2020-01-21 09:18:51.478 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, lastVisibleItem: 3
2020-01-21 09:18:51.478 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, 滚动到最后一行
2020-01-21 09:18:51.493 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:18:51.494 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, onScroll, firstVisibleItem: 3, visibleItemCount: 8, totalItemCount: 11
2020-01-21 09:18:51.494 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, lastVisibleItem: 3
2020-01-21 09:18:51.494 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, 滚动到最后一行
2020-01-21 09:18:51.510 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:18:51.527 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:18:51.760 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:18:51.765 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:18:51.767 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_UP
2020-01-21 09:18:51.771 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, SCROLL_STATE_IDLE
2020-01-21 09:18:54.455 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_DOWN
2020-01-21 09:18:54.468 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:18:54.483 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:18:54.499 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:18:54.550 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:18:54.552 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, SCROLL_STATE_TOUCH_SCROLL
2020-01-21 09:18:54.553 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, onScroll, firstVisibleItem: 3, visibleItemCount: 8, totalItemCount: 11
2020-01-21 09:18:54.553 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, lastVisibleItem: 3
2020-01-21 09:18:54.553 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, 滚动到最后一行
2020-01-21 09:18:54.566 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:18:54.567 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, onScroll, firstVisibleItem: 3, visibleItemCount: 8, totalItemCount: 11
2020-01-21 09:18:54.567 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, lastVisibleItem: 3
2020-01-21 09:18:54.567 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, 滚动到最后一行
2020-01-21 09:18:54.583 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:18:54.584 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, onScroll, firstVisibleItem: 3, visibleItemCount: 7, totalItemCount: 11
2020-01-21 09:18:54.584 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, lastVisibleItem: 3
2020-01-21 09:18:54.601 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:18:54.602 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, onScroll, firstVisibleItem: 3, visibleItemCount: 7, totalItemCount: 11
2020-01-21 09:18:54.602 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, lastVisibleItem: 3
2020-01-21 09:18:54.617 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:18:54.618 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, onScroll, firstVisibleItem: 3, visibleItemCount: 7, totalItemCount: 11
2020-01-21 09:18:54.618 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, lastVisibleItem: 3
2020-01-21 09:18:54.634 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:18:54.635 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, onScroll, firstVisibleItem: 3, visibleItemCount: 7, totalItemCount: 11
2020-01-21 09:18:54.635 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, lastVisibleItem: 3
2020-01-21 09:18:54.649 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:18:54.651 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, onScroll, firstVisibleItem: 3, visibleItemCount: 7, totalItemCount: 11
2020-01-21 09:18:54.651 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, lastVisibleItem: 3
2020-01-21 09:18:54.667 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:18:54.669 32227-32227/com.example.sourcecodetest D/ViewHolderAdapter: zwm, getView: 1
2020-01-21 09:18:54.674 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, onScroll, firstVisibleItem: 2, visibleItemCount: 7, totalItemCount: 11
2020-01-21 09:18:54.674 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, lastVisibleItem: 3
2020-01-21 09:18:54.674 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, 下滑
2020-01-21 09:18:54.683 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:18:54.685 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, onScroll, firstVisibleItem: 2, visibleItemCount: 7, totalItemCount: 11
2020-01-21 09:18:54.685 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, lastVisibleItem: 2
2020-01-21 09:18:54.700 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:18:54.701 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, onScroll, firstVisibleItem: 2, visibleItemCount: 7, totalItemCount: 11
2020-01-21 09:18:54.701 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, lastVisibleItem: 2
2020-01-21 09:18:54.717 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:18:54.718 32227-32227/com.example.sourcecodetest D/ViewHolderAdapter: zwm, getView: 0
2020-01-21 09:18:54.723 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, onScroll, firstVisibleItem: 1, visibleItemCount: 8, totalItemCount: 11
2020-01-21 09:18:54.723 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, lastVisibleItem: 2
2020-01-21 09:18:54.723 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, 下滑
2020-01-21 09:18:54.725 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:18:54.727 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_UP
2020-01-21 09:18:54.728 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, SCROLL_STATE_FLING
2020-01-21 09:18:54.732 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, onScroll, firstVisibleItem: 1, visibleItemCount: 8, totalItemCount: 11
2020-01-21 09:18:54.732 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, lastVisibleItem: 1
2020-01-21 09:18:54.736 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, onScroll, firstVisibleItem: 1, visibleItemCount: 8, totalItemCount: 11
2020-01-21 09:18:54.736 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, lastVisibleItem: 1
2020-01-21 09:18:54.750 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, onScroll, firstVisibleItem: 1, visibleItemCount: 7, totalItemCount: 11
2020-01-21 09:18:54.750 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, lastVisibleItem: 1
2020-01-21 09:18:54.767 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, onScroll, firstVisibleItem: 1, visibleItemCount: 7, totalItemCount: 11
2020-01-21 09:18:54.767 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, lastVisibleItem: 1
2020-01-21 09:18:54.783 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, onScroll, firstVisibleItem: 1, visibleItemCount: 7, totalItemCount: 11
2020-01-21 09:18:54.783 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, lastVisibleItem: 1
2020-01-21 09:18:54.801 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, onScroll, firstVisibleItem: 0, visibleItemCount: 8, totalItemCount: 11
2020-01-21 09:18:54.801 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, lastVisibleItem: 1
2020-01-21 09:18:54.801 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, 下滑
2020-01-21 09:18:54.817 32227-32227/com.example.sourcecodetest D/ViewHolderAdapter: zwm, getView: 6
2020-01-21 09:18:54.821 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, onScroll, firstVisibleItem: 0, visibleItemCount: 8, totalItemCount: 11
2020-01-21 09:18:54.821 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, lastVisibleItem: 0
2020-01-21 09:18:55.003 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, SCROLL_STATE_IDLE
2020-01-21 09:18:59.182 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_DOWN
2020-01-21 09:18:59.192 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:18:59.208 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:18:59.225 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:18:59.243 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:18:59.245 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, SCROLL_STATE_TOUCH_SCROLL
2020-01-21 09:18:59.258 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:18:59.275 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:18:59.326 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:18:59.339 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:18:59.341 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_UP
2020-01-21 09:18:59.343 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, SCROLL_STATE_IDLE
2020-01-21 09:19:01.810 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_DOWN
2020-01-21 09:19:01.827 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:19:01.881 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:19:01.883 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, SCROLL_STATE_TOUCH_SCROLL
2020-01-21 09:19:01.897 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:19:02.181 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:19:02.200 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:19:02.283 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:19:02.298 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:19:02.432 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:19:02.465 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:19:02.482 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:19:02.617 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:19:02.629 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_MOVE
2020-01-21 09:19:02.630 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, MotionEvent.ACTION_UP
2020-01-21 09:19:02.633 32227-32227/com.example.sourcecodetest D/MainActivity: zwm, SCROLL_STATE_IDLE

相关链接

ListView和RecyclerView原理简析

你可能感兴趣的:(控件 -- ListView)