[英]How to put drawable in the middle of textView on android java
I can't find information on how to draw image in the middle of texview using drawable.我找不到有关如何使用 drawable 在 texview 中间绘制图像的信息。 Below Images on how the app looks like atht he moment
下面的图片显示了该应用程序的外观
When the knight should be in the middle of box (textView).当骑士应该在盒子的中间时(textView)。 I have created my textviews dynamicly with loops so accessing XML file is not possible.
我已经使用循环动态创建了我的文本视图,因此无法访问 XML 文件。 I am using
textView.setCompoundDrawablesRelativeWithIntrinsicBounds(ic_horsey, 0, 0, 0 )
to draw the image.我正在使用
textView.setCompoundDrawablesRelativeWithIntrinsicBounds(ic_horsey, 0, 0, 0 )
来绘制图像。
TextView
are not used to display Drawables. TextView
不用于显示 Drawable。 You have to use an ImageView
for that.为此,您必须使用
ImageView
。
Regarding your screenshot, a LinearLayout
containing a TextView
for the letter and an ImageView
for the chess piece will do the job to represent a chess cell关于您的屏幕截图,包含
TextView
的字母和ImageView
的棋子的LinearLayout
将完成代表国际象棋单元的工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.