android - 如何在 android.. 的 Canvas 上绘制 TextView?

标签 android

如何在 android.. 的 Canvas 上绘制 TextView?

我们有 Canvas.DrawBitmap()Canvas.drawText()。 Canvas 中是否有任何将 TextView 作为参数的方法或任何其他方法在 Canvas 上显示 TextView?

实际上,我在 TextView 中有一个字母表,我必须在 Canvas 中的那个字母表上进行绘图。

请提出任何建议....感谢您的合作

最佳答案

Textview 不能直接画,但是可以放在一个布局中,然后 Canvas 局。像这样的:

LinearLayout layout = new LinearLayout(context);

TextView textView = new TextView(context); 
textView.setVisibility(View.VISIBLE);
textView.setText("Hello world");
layout.addView(textView);

layout.measure(canvas.getWidth(), canvas.getHeight());
layout.layout(0, 0, canvas.getWidth(), canvas.getHeight());

// To place the text view somewhere specific:
//canvas.translate(0, 0);

layout.draw(canvas);

关于android - 如何在 android.. 的 Canvas 上绘制 TextView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5242757/

相关文章:

java - ActionBar 选项卡和 ViewPager 的多 fragment 布局

java - 使用字符串引用属性

android - ListView 和表格布局有什么区别?

android - 子剪辑:相同的用户 ID,不同的机器

android - Gradle同步失败:找不到com.android.tools.build:gradle:5.6.4

Android复杂布局设计建议

java - Android MainDexClassList 构建错误

android - 如何使 TextView 闪烁

android - 从图像 URL 获取缩略图 URL

java - 如何让我的 ArrayAdapter 遵循 ViewHolder 模式?