[Android实例] 侧边字母滑动检索控件
来源:互联网 发布:我的世界天堂js怎么用 编辑:程序博客网 时间:2024/06/05 02:04
该篇文章从eoeAndroid搬迁过来的,原文地址:[Android实例] 侧边字母滑动检索控件
自定义侧边滑动检索控件,能根据A~Z字母进行检索,类似微信,通讯录右侧字母检索方式
主要代码:
@Override protected void onDraw(Canvas canvas) { // TODO Auto-generated method stub super.onDraw(canvas); // 获取焦点改变背景颜色 int height = getHeight(); int width = getWidth(); int sigleHeight = height / b.length; for (int i = 0; i < b.length; i++) { paint.setColor(Color.BLACK); paint.setTypeface(Typeface.DEFAULT_BOLD); paint.setAntiAlias(true); paint.setTextSize(20); // 选中状态 if (i == position) { paint.setColor(Color.BLUE); paint.setTextSize(30); paint.setFakeBoldText(true); } // x坐标等于中间-字符串宽度的一半. float xPos = width / 2 - paint.measureText(b[i]) / 2; float yPos = sigleHeight * i + sigleHeight; canvas.drawText(b[i], xPos, yPos, paint); paint.reset();// 重置画笔 } } @SuppressWarnings("deprecation") @Override public boolean dispatchTouchEvent(MotionEvent event) { // TODO Auto-generated method stub int action = event.getAction(); float y = event.getY() - getY(); int oldPosition = position; // 点击y坐标所占总高度的比例*b数组的长度就等于点击b中的个数. int c = 0; if (y >= 0 && y <= getHeight()) { c = (int) (y / getHeight() * b.length); } else if (y > getHeight()) { c = b.length - 1; } if (action == MotionEvent.ACTION_UP) { setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); position = -1; if (showChooseText != null) { showChooseText.setVisibility(View.INVISIBLE); } } else { setBackgroundDrawable(new ColorDrawable(Color.GRAY)); setBackgroundColor(Color.GRAY); if (oldPosition != c) { if (c >= 0 && c < b.length) { if (onTouchingChangedListener != null) { onTouchingChangedListener.onTouchingChanged(b[c]); } } if (showChooseText != null) { showChooseText.setText(b[c]); showChooseText.setVisibility(View.VISIBLE); } position = c; } } invalidate(); return true; }
下载地址:项目代码
0 0
- [Android实例] 侧边字母滑动检索控件
- android自定义View之仿通讯录侧边栏滑动,实现A-Z字母检索
- android自定义View之仿通讯录侧边栏滑动,实现A-Z字母检索
- android自定义View之仿通讯录侧边栏滑动,实现A-Z字母检索
- Android自定义屏幕侧边字母排序控件
- 自定义View之仿通讯录侧边栏滑动,实现A-Z字母检索
- [Android实例] 仿微信通讯录,A~Z拼音侧边检索
- Android ListView侧边字母索引栏SideBar控件的实现
- android:滑动侧边栏
- Android滑动侧边栏
- Android侧边滑动菜单
- android开发实例02:列表字母索引与过滤检索
- Android 仿微信通讯录的字母快速检索控件
- android 滑动侧边栏 SlideMenu
- Android双向侧边滑动实现
- ionic中的分类侧边栏ABC字母滑动特效
- Android 侧边字母导航栏的实现
- Android 带字母索引的侧边栏
- Java 对象拷贝
- UISwitch的默认宽高51*31,UITabBarController的默认高度是49
- 《iOS Human Interface Guidelines》——Multitasking
- 分析京东“搜索京东商品/店铺”布局(一)
- Cocos在windows7下的配置与apk打包
- [Android实例] 侧边字母滑动检索控件
- 在commit之前撤销git add操作 (undo git add before commit)
- 改变webkit 内核滚动条宽度
- mysql 语句集锦
- ios中摇一摇功能的使用
- 172,使用screenium,GIFBrewery制作gif动态图
- (五)黑马程序员——Java中的字符串操作类(String、StringBuilder、StringBuffer)
- activemq+spring 持久化发送消息
- C++语言为什么跨平台?