android - 如何在 kotlin 中创建视图并将 TextView 放入其中
问题描述
我想通过代码在 kotlin 中的 View 对象中添加 TextView
我确实创建了视图,但我无法在其中添加文本视图
val view1 : View
view1 = View(this)
myLayout.addView(view1)
view1.layoutParams.height = (Height * 0.35).toInt()
view1.layoutParams.width = (Width * 0.8).toInt()
view1.x = (1+ Width*0.10).toFloat()
view1.y = (Height*0.15).toFloat()
view1.setBackgroundColor(Color.rgb(128,0,128))
解决方案
val view1 : TextView = TextView(this)
myLayout.addView(view1)
view1.layoutParams.height = (Height * 0.35).toInt()
view1.layoutParams.width = (Width * 0.8).toInt()
view1.x = (1+ Width*0.10).toFloat()
view1.y = (Height*0.15).toFloat()
view1.text = "Some text"
view1.setBackgroundColor(Color.rgb(128,0,128))
推荐阅读
- html - 如何将社交图标放在一起?
- arrays - Twig 将变量解释为字符串并且不读取它们的内容
- odoo - ODOO 14 如何在模板 website_sale.cart_lines 中显示产品模型中的字段
- javascript - 如何将 Python 切片赋值语法移植到 JavaScript/TypeScript?
- c++ - RGB 到十六进制语法
- numpy - scipy 插值二维数组
- security - 有人试图访问我的 Facebook 帐户
- php - file_get_contents 适用于 php7.2 但不适用于 php7.3 或 7.4
- javascript - 使用 toDataURL() 的污染画布的 Javascript CORS 问题
- django - 在 django 媒体中保存图像文件而不是在 quill 编辑器中使用 base64?