设置包含文本的自定义视图的样式或字体,例如默认的 TextView?
我正在实现一个包含文本的自定义视图,文本将在 onDraw 中绘制。
我的问题是,我希望我的文本看起来像 TextView 对象中的文本,但我对设置样式和字体并不熟悉。
最终用我的新 Paint 对象绘制的文本,看起来与 TextView 不同:线条看起来更细,似乎被一些昆虫咬了...... - -b。我希望我的文本能够像那些 TextView 对象一样绘制。
请帮忙!
====================
换句话说,问题是:
在扩展 View 的自定义视图中,我在 onDraw 方法中调用 mPaint.drawText,并使用新的 Paint 对象 mPaint。但是绘制出来的文字看起来和默认的TextView不一样,线条比较细而且不平滑(就像被虫子咬了一样)。我只是希望它与 TextView 具有相同的外观。
I`m implementing a custom view which contains text, and the text will be drawn in onDraw.
My problem is, I wish my text will looks like those in the TextView objects, but I`m not quit familiar with setting up the style and typeface.
The text finally drawn with my fresh new Paint object, looks different from TextView: The lines looks thinner and seems bitten by some insects... - -b. I wish my text will be drawn just like those TextView objects.
Plz help!
====================
The problem in other words:
In a custom view extending View, I call mPaint.drawText in the onDraw method, with a new Paint object mPaint. But the text drawn looks different to the default TextView, the lines are thinner and not smooth(like were bitten by some insects). I just want it to be the same look as TextView.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
现在在您的 class/xml 中使用
CustomText
。希望这会对您有所帮助。
Now use the
CustomText
in your class/xml.Hope this will help you.
您可以通过将 TextView 扩展为父视图来创建自定义视图。通过这样做,您将获得 textView 具有的所有默认功能,此外您还可以根据您的要求添加其他自定义功能。
You can create a custom view by extending TextView as a parent view. by doing this you will get all the default features that textView has and plus you can add other custom features as per your requirements.