日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

QuickIndex 通讯录快速检索

發布時間:2023/12/20 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 QuickIndex 通讯录快速检索 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

QuickIndex 通訊錄快速檢索

歡迎入群交流

public class QuickIndexBar extends View {private String[] indexArr = {"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"};Paint paint = null;int ColorDefault = Color.GRAY;//默認顏色int ColorPressed = Color.BLUE;//按下顏色public QuickIndexBar(Context context) {this(context, null);}public QuickIndexBar(Context context, @Nullable AttributeSet attrs) {this(context, attrs, 0);}public QuickIndexBar(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {super(context, attrs, defStyleAttr);paint = new Paint(Paint.ANTI_ALIAS_FLAG);//設置抗鋸齒paint.setColor(ColorDefault);int size = getResources().getDimensionPixelSize(R.dimen.text_size);paint.setTextSize(size);//文字繪制的默認起點是文字的左下角,CENTER表示底邊的中心,而不是正中心paint.setTextAlign(Paint.Align.CENTER);//Baseline:基準線}float cellHeight;//一個格子的高度@Overrideprotected void onSizeChanged(int w, int h, int oldw, int oldh) {super.onSizeChanged(w, h, oldw, oldh);cellHeight = getMeasuredHeight() * 1f / indexArr.length;}@Overrideprotected void onDraw(Canvas canvas) {//遍歷繪制26個字母for (int i = 0; i < indexArr.length; i++) {String text = indexArr[i];float x = getMeasuredWidth() / 2;//整個寬的一半//格子高度一半+文字高度一半+i*格子高度int textHeight = getTextHeight(text);float y = cellHeight / 2 + textHeight / 2 + i * cellHeight;//變色paint.setColor(i == index ? ColorPressed : ColorDefault);canvas.drawText(text, x, y, paint);}}int index = -1;//用來記錄觸摸的索引的@Overridepublic boolean onTouchEvent(MotionEvent event) {switch (event.getAction()) {case MotionEvent.ACTION_DOWN:case MotionEvent.ACTION_MOVE:int temp = (int) (event.getY() / cellHeight);if (temp != index) {index = temp;//對index進行一下安全性的檢查if (index >= 0 && index < indexArr.length) {String word = indexArr[index];if (listener != null) {listener.onLetterChange(word);}}}break;case MotionEvent.ACTION_UP://抬起重置變量index = -1;break;}//重繪invalidate();return true;}/*** 獲取文字的高度** @param text* @return*/private int getTextHeight(String text) {Rect bounds = new Rect();paint.getTextBounds(text, 0, text.length(), bounds);//對bounds進行賦值return bounds.height();}private OnLetterChangeListener listener;public void setOnLetterChangeListener(OnLetterChangeListener listener) {this.listener = listener;}public interface OnLetterChangeListener {void onLetterChange(String word);}}

微信公眾號(他曉),關注并轉發,謝謝

總結

以上是生活随笔為你收集整理的QuickIndex 通讯录快速检索的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。