开发工具:
文件大小: 199kb
下载次数: 0
上传时间: 2015-03-06
详细说明: public class MySideBar extends View{ OnTouchingLetterChangedListener onTouchingLetterChangedListener; 按住改变背景色 private boolean showBkg; public static String[] b { "热" "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O&q uot; "P" "Q" "R" "S" "T" "U" "V" "W" "X" "Y" "Z" }; 被选中位置 int choose 1; private Paint paint new Paint ; public MySideBar Context context { super context ; } public MySideBar Context context AttributeSet attrs int defStyle { super context attrs defStyle ; } public MySideBar Context context AttributeSet attrs { super context attrs ; } protected void onDraw Canvas canvas { super onDraw canvas ; if showBkg { canvas drawColor Color parseColor "#ccddFF" ; } float height getHeight ; float width getWidth ; 计算单个字母高度 float singleHeight height float b length ; for int i 0; i < b length; i++ { paint setColor Color BLACK ; if i choose { 选中的颜色 paint setColor Color parseColor "#3399ff" ; 加粗 paint setFakeBoldText true ; } 设置文本坐标 float xPos width 2 paint measureText b[i] 2; float yPos singleHeight i + singleHeight; canvas drawText b[i] xPos yPos paint ; paint reset ; } } public boolean dispatchTouchEvent MotionEvent event { int action event getAction ; float y event getY ; final int oldChoose choose; final int c int y getHeight b length ; final OnTouchingLetterChangedListener listener onTouchingLetterChangedListener; switch action { case MotionEvent ACTION DOWN: showBkg true; if oldChoose c && listener null { if c > 0 && c < b length { listener onTouchingLetterChanged c ; choose c; invalidate ; } } break; case MotionEvent ACTION MOVE: if oldChoose c && listener null { if c > 0 && c < b length { listener onTouchingLetterChanged c ; choose c; invalidate ; } } break; case MotionEvent ACTION UP: showBkg false; choose 1; invalidate ; break; } return true; } public void setOnTouchingLetterChangedListener OnTouchingLetterChangedListener onTouchingLetterChangedListener { this onTouchingLetterChangedListener onTouchingLetterChangedListener; } public interface OnTouchingLetterChangedListener { public void onTouchingLetterChanged int s ; }">public class MySideBar extends View{ OnTouchingLetterChangedListener onTouchingLetterChangedListener; 按住改变背景色 private boolean showBkg; public static String[] b { "热" "A" "B" "C" "D" "E" "F" "G&q [更多] ...展开收缩
(系统自动生成,下载前可以参看下载内容)
下载文件列表
相关说明
- 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
- 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度。
- 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
- 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
- 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
- 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.