Android TextView字幕效果实例
作者:whsnow 时间:2022-03-18 14:55:13
一、效果图
二、代码
public class TextSubView extends TextView {
private TextPaint mPaint;
public TextSubView(Context context, AttributeSet attrs) {
super(context, attrs);
mPaint = new TextPaint(getPaint());
mPaint.setStyle(TextPaint.Style.STROKE);
mPaint.setShadowLayer(2.0F, 2.0F, 2.0F, Color.RED);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.save();
canvas.clipRect(0, 0, 55, getBottom());
canvas.drawText(getText().toString(), 0, getBaseline(), mPaint);
canvas.restore();
}
}
代码说明:
关键是setShadowLayer设置阴影效果以及onDraw的四行代码,大家可以搜一下"Android clipRect"了解一下这个函数的作用,注意clipRect与drawText的顺序不要弄反了。
标签:Android,TextView,字幕
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
ShardingSphere解析SQL示例详解
2023-11-23 13:57:55
利用Lambda表达式创建新线程案例
2023-08-26 23:16:00
C#图像伪彩色处理方法
2022-09-23 10:51:52
![](https://img.aspxhome.com/file/2023/1/92911_0s.jpg)
Android编程之重力感应用法分析
2021-09-04 19:49:35
Kotlin之在Gradle中无参(no-arg)编译器插件的使用详解
2023-07-31 19:11:43
Spring中事务几个常见的问题解决
2022-04-07 00:52:01
浅谈SpringCache与redis集成实现缓存解决方案
2022-10-12 01:11:17
![](https://img.aspxhome.com/file/2023/8/95958_0s.png)
探讨如何用委托处理排序
2023-12-17 15:06:36
eclipse 中的javac命令与java命令
2023-08-19 14:16:57
![](https://img.aspxhome.com/file/2023/2/67622_0s.png)
javascript 在线文本编辑器实现代码
2023-11-24 23:07:24
SpringBoot资源文件的存放位置设置方式
2023-02-26 10:37:00
![](https://img.aspxhome.com/file/2023/0/84240_0s.png)
IntelliJ IDEA安装目录和设置目录的说明(IntelliJ IDEA快速入门)
2021-08-16 21:17:08
![](https://img.aspxhome.com/file/2023/2/86802_0s.jpg)
Jsoup解析html实现招聘信息查询功能
2022-01-08 19:38:07
![](https://img.aspxhome.com/file/2023/9/64929_0s.png)
一文搞懂Mybatis-plus的分页查询操作
2023-11-25 10:23:17
C#的TimeSpan案例详解
2023-11-20 11:34:52
![](https://img.aspxhome.com/file/2023/7/88317_0s.png)
C#实现绑定Combobox的方法
2023-02-16 03:49:48
Java基于分治法实现的快速排序算法示例
2023-12-15 07:39:06
![](https://img.aspxhome.com/file/2023/2/66642_0s.jpg)
ImportBeanDefinitionRegistrar手动控制BeanDefinition创建注册详解
2021-11-11 18:49:18
Spring如何使用@Indexed加快启动速度
2022-05-02 10:50:40
![](https://img.aspxhome.com/file/2023/6/62236_0s.jpg)
Java-JFrame-swing嵌套浏览器的具体步骤
2022-11-26 19:30:10