网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

Android仿微信通讯录滑动快速定位功能-创新互联

先给大家展示下效果图:

在七星等地区,都构建了全面的区域性战略布局,加强发展的系统性、市场前瞻性、产品创新能力,以专注、极致的服务理念,为客户提供成都网站设计、成都做网站 网站设计制作按需网站策划,公司网站建设,企业网站建设,品牌网站设计,营销型网站,成都外贸网站建设,七星网站建设费用合理。

实现代码如下:

下面简单说下实现原理。

public class IndexBar extends LinearLayout implements View.OnTouchListener {
  private static final String[] INDEXES = new String[]{"#", "A", "B", "C", "D", "E", "F", "G", "H",
      "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"};
  private static final int TOUCHED_BACKGROUND_COLOR = 0x40000000;
  private OnIndexChangedListener mListener;
  public void setOnIndexChangedListener(OnIndexChangedListener listener) {
    mListener = listener;
  }
  public IndexBar(Context context) {
    this(context, null);
  }
  public IndexBar(Context context, AttributeSet attrs) {
    this(context, attrs, 0);
  }
  public IndexBar(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    init(attrs);
  }
  private void init(AttributeSet attrs) {
    TypedArray ta = getContext().obtainStyledAttributes(attrs, R.styleable.IndexBar);
    float indexTextSize = ta.getDimension(R.styleable.IndexBar_indexTextSize, Utils.sp2px(getContext(), 12));
    int indexTextColor = ta.getColor(R.styleable.IndexBar_indexTextColor, 0xFF616161);
    ta.recycle();
    setOrientation(VERTICAL);
    setOnTouchListener(this);
    for (String index : INDEXES) {
      TextView text = new TextView(getContext());
      text.setText(index);
      text.setTextSize(TypedValue.COMPLEX_UNIT_PX, indexTextSize);
      text.setTextColor(indexTextColor);
      text.setGravity(Gravity.CENTER);
      LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 1);
      text.setLayoutParams(params);
      addView(text);
    }
  }
  @Override
  public boolean onTouch(View v, MotionEvent event) {
    switch (event.getAction()) {
      case MotionEvent.ACTION_DOWN:
        setBackgroundColor(TOUCHED_BACKGROUND_COLOR);
        handle(v, event);
        return true;
      case MotionEvent.ACTION_MOVE:
        handle(v, event);
        return true;
      case MotionEvent.ACTION_UP:
        setBackgroundColor(Color.TRANSPARENT);
        handle(v, event);
        return true;
    }
    return super.onTouchEvent(event);
  }
  private void handle(View v, MotionEvent event) {
    int y = (int) event.getY();
    int height = v.getHeight();
    int position = INDEXES.length * y / height;
    if (position < 0) {
      position = 0;
    } else if (position >= INDEXES.length) {
      position = INDEXES.length - 1;
    }
    String index = INDEXES[position];
    boolean showIndicator = event.getAction() != MotionEvent.ACTION_UP;
    if (mListener != null) {
      mListener.onIndexChanged(index, showIndicator);
    }
  }
  public interface OnIndexChangedListener {
    void onIndexChanged(String index, boolean showIndicator);
  }
}

网站栏目:Android仿微信通讯录滑动快速定位功能-创新互联
当前URL:http://bjjierui.cn/article/jogcg.html

其他资讯