[英]How add TextView to View in kotlin
I have button when click I want to show (View) and inside it textview I did view but I can't add to it textView inside it 单击时我有一个按钮,我想显示(查看),并且在其中查看textview我查看过,但是无法在其中添加textView
fun you_color_button_1(view: View){
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 name_label1 =TextView(this)
myLayout.addView(name_label1)
la.addView(name_label1)
name_label1!!.layoutParams.height = (la.width * 0.20).toInt()
name_label1!!.layoutParams.width = (la.height * 0.10).toInt()
name_label1!!.x = (1+la.width * 0.75).toFloat()
name_label1!!.y = (la.height * 0.15).toFloat()
name_label1.text = "name"
name_label1.textSize = (Width * 0.014).toFloat()
name_label1.setTextColor(Color.WHITE)
name_label1.setTypeface(null,Typeface.BOLD)
name_label1.gravity = Gravity.CENTER
}
and too I want corner radius for View by code 我也想通过代码查看的拐角半径
When you click on a button like as You mentioned in below https://i.stack.imgur.com/UgRzA.png You should add that view as you want in your current xml and make that view's visibility Gone... Then when you click on a button on click event validate the data as you want and directly make that view's visibility to visible. 当您单击下面在https://i.stack.imgur.com/UgRzA.png中提到的按钮时,应在当前xml中根据需要添加该视图,并使该视图的可见性消失。您单击单击事件上的按钮即可根据需要验证数据,并直接使该视图的可见性可见。 I hope it helps. 希望对您有所帮助。
initially view's visibility -> 初始视图的可见性->
yourView.visibility = View.GONE
btn.setOnClickListener{
YourView.visibility = View.VISIBLE
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.