zoukankan      html  css  js  c++  java
  • ListView 源码学习笔记 [ 原创 ]

    ListView 源码学习笔记

    public class ListView extends AbsListView {
    /**
    * Used to indicate a no preference for a position type.
       * 指示一个没有被引用的位置
    */
    static final int NO_POSITION = -1;

    /**
    * Normal list that does not indicate choices
       * 普通列表显示(没有指定显示模式)
    */
        public static final int CHOICE_MODE_NONE = 0;

    /**
    * The list allows up to one choice
       * 单选模式
    */
    public static final int CHOICE_MODE_SINGLE = 1;

    /**
    * The list allows multiple choices
       * 多选模式
    */
    public static final int CHOICE_MODE_MULTIPLE = 2;

    /**
    * When arrow scrolling, ListView will never scroll more than this factor times the height of the list.
    *
    */
    private static final float MAX_SCROLL_FACTOR = 0.33f;

    /**
    * When arrow scrolling, need a certain amount of pixels to preview next items. This is usually the fading edge,
    * but if that is small enough, we want to make sure we preview at least this many pixels.
    *
    */
    private static final int MIN_SCROLL_PREVIEW_PIXELS = 2;

    还有一些用到的重要的类和方法

    public void setSelection(int position)

    public void setCacheColorHint(int color)

    public void setChoiceMode(int choiceMode)

    public boolean performItemClick(View view, int position, long id)

    public void setItemChecked(int position, boolean value)

    下面的 mIsCacheColorOpaque 是与背景透明色相关的东西.

    private boolean mIsCacheColorOpaque;

    @Override
    public boolean isOpaque() {
      return (mCachingStarted && mIsCacheColorOpaque && mDividerIsOpaque &&
        hasOpaqueScrollbars()) || super.isOpaque();
    }

    @Override
    public void setCacheColorHint(int color) {
      final boolean opaque = (color >>> 24) == 0xFF;
      mIsCacheColorOpaque = opaque;
      if (opaque) {
        if (mDividerPaint == null) {
          mDividerPaint = new Paint();
        }
        mDividerPaint.setColor(color);
      }
      super.setCacheColorHint(color);
    }

    下面的

    /**
    * SparseBooleanArrays map integers to booleans. Unlike a normal array of booleans there can be gaps in the indices.
    * It is intended to be more efficient than using a HashMap to map Integers to Booleans.
    * 对于从 Integer 到 Boolean 的映射, 使用 SparseBooleanArrays 比 HashMap 更有效率.
    */
    private SparseBooleanArray mCheckStates;
    private LongSparseArray<Boolean> mCheckedIdStates;

    public void setChoiceMode(int choiceMode) {
      mChoiceMode = choiceMode;
      if (mChoiceMode != CHOICE_MODE_NONE) {
        if (mCheckStates == null) {
          mCheckStates = new SparseBooleanArray();
        }
        if (mCheckedIdStates == null && mAdapter != null && mAdapter.hasStableIds()) {
          mCheckedIdStates = new LongSparseArray<Boolean>();
        }
      }
    }







  • 相关阅读:
    python读取数据写入excel
    English Study!
    ODOO里视图开发案例---定义一个像tree、form一样的视图
    更改gradle中央仓库,加快访问速度
    hadoop解决集群启动时某个slave的datanode挂掉问题
    ssh免密登录
    大数据集群脚本xcall和xsync
    虚拟机启动后黑屏并无法关闭
    快照与克隆的区别(来自转载)
    VMware12 打不开Centos6.8系统
  • 原文地址:https://www.cnblogs.com/xpxpxp2046/p/2313225.html
Copyright © 2011-2022 走看看