android TextView遇到的问题
来源:互联网 发布:洪恩软件开天辟地7 编辑:程序博客网 时间:2024/05/19 17:50
1.高亮显示TextView的文本内容。
ssb.setSpan(new BackgroundColorSpan(mContext.getResources().getColor(R.color.bg_yellow1)),
start,end,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
当文本内容中包含ImageSpan,会出现
产生问题的原因:
文字:
c.drawTextRun(mChars, start, count, contextStart, contextCount,
x, y, flags, wp);
图片:
Drawable b = getCachedDrawable();
canvas.save();
int transY = bottom - b.getBounds().bottom;
if (mVerticalAlignment == ALIGN_BASELINE) {
transY -= paint.getFontMetricsInt().descent;
}
canvas.translate(x, transY);
b.draw(canvas);
canvas.restore();
可以看出:文字,图片画在画布的不同位置上,而BackgroundColorSpan是在改变drawTextRun()的TextPaint对象wp.bgColor
解决方法:
自定义ImageSpan,重写ImageSpan.draw()方法
Drawable b = getDrawable(); canvas.save(); int transY = bottom - b.getBounds().bottom; if (mVerticalAlignment == ALIGN_BASELINE) { transY -= paint.getFontMetricsInt().descent; } paint.setColor(bgColor); Rect r = new Rect((int) x, top, (int) (x + (b.getBounds().right - b.getBounds().left)), bottom); canvas.drawRect(r, paint); canvas.translate(x, transY); b.draw(canvas); canvas.restore();
2.TextView的网址URLSpan click与long click冲突, 执行了longclick,还执行了click
产生问题的原因:
URLSpan.onClick 是在onTouchEvent中, action=ACTION_UP时,
而longclick是在action=ACTION_DOWN时,postDelay(Runnable),在Runnable中执行onLongClick
解决方法:
因此需要在onLongClick发生时,作出标记,
当action=ACTION_UP时,根据标记判断是否还要执行click
- android TextView遇到的问题
- android textview drawableleft使用时遇到的问题
- TextView 遇到的相关问题及解决方法
- 开发中TextView遇到的问题
- 做textview的字数限制时遇到的问题
- (项目遇到的textview排版问题的亲测解决方案)
- Android遇到的问题
- android遇到的问题
- android遇到的问题
- ListView 中Item TextView 跑马灯遇到的问题
- 解决textview遇到标点自动换行的问题
- recyclerview中的 TextView 跑马灯遇到的一个问题
- 诡异的Android TextView排版布局问题
- android TextView 显示字数的限制问题
- Android textview 显示不全的问题
- 解决Android的TextView排版问题
- 解决Android TextView默认的padding问题
- android动态设置TextView的textColor问题
- SQL server 数据库查询
- java学习之路之基本语法-运算符练习题
- SQL server 数据库查询
- 数据库——报错:ORA-01861: 文字与格式字符串不匹配
- PreparedStatement与Statement理解
- android TextView遇到的问题
- java学习之路之基本语法-程序流程控制
- java if语句练习
- 《Spark商业案例与性能调优实战100课》第1课:商业案例之通过RDD实现分析大数据电影点评系统中电影的用户行为信息
- Windows 平台运行spark-shell 报"java.lang.NullPointerException, not found: value sqlContext" error 解决办法
- [1]《微交互》读感 —— 往小处想,改变世界!
- WindowsPowerShell 出现无法识别cmdlet、函数、脚本等错误
- Java注解处理器 - 五分钟快速入门
- opencv学习笔记(十四)图像金字塔