Android 如何更改Kotlin中按钮的位置和尺寸
我们正在创建在循环中调用以下函数的按钮。 问题是我们给出的尺寸和坐标没有被使用。 安卓显然在放置它们时使用了其他一些逻辑Android 如何更改Kotlin中按钮的位置和尺寸,android,kotlin,Android,Kotlin,我们正在创建在循环中调用以下函数的按钮。 问题是我们给出的尺寸和坐标没有被使用。 安卓显然在放置它们时使用了其他一些逻辑 fun createAButton( name: ArrayList<Button>, x: Float, y: Float, w: Int, h: Int){ name.a
fun createAButton(
name: ArrayList<Button>,
x: Float,
y: Float,
w: Int,
h: Int){
name.add(Button(this))
var index = name.size - 1
myActionMenuView.addView(name[index])
name[index].width = w
name[index].height = h
name[index].x = x
name[index].y = y
}
fun createAButton(
名称:ArrayList,
x:浮动,
y:浮动,
w:Int,
h:Int){
名称.添加(按钮(此))
var index=name.size-1
myActionMenuView.addView(名称[索引])
名称[索引].width=w
名称[索引]。高度=h
名称[索引].x=x
名称[索引].y=y
}
试试看,这对你很有用
fun createAButton(
name: ArrayList<Button>,
x: Float,
y: Float,
w: Int,
h: Int){
name.add(Button(this))
var index = name.size - 1
myActionMenuView.addView(name[index])
name[index].width = w
name[index].height = h
name[index].x = x
name[index].y = y
name[index].layoutParams = LinearLayout.LayoutParams(w,h)
}
fun createAButton(
名称:ArrayList,
x:浮动,
y:浮动,
w:Int,
h:Int){
名称.添加(按钮(此))
var index=name.size-1
myActionMenuView.addView(名称[索引])
名称[索引].width=w
名称[索引]。高度=h
名称[索引].x=x
名称[索引].y=y
名称[索引].layoutParams=LinearLayout.layoutParams(w,h)
}
使用LayoutParams设置高度和宽度当我使用最后一行时,您建议应用程序不运行,我看到应用程序一直停止窗口。A执行了以下操作。50后,value.width和value.Height的值为-1,但按钮的外观并没有改变。var value=name[index].getLayoutParams()value.width=50 value.height=50 name[index].setLayoutParams(value)我想知道应该在哪里使用button.x,button.y,button.width,button.height。因为我在TextView中使用了相同的结构,并且它是有效的。发生了什么,我们不能在一个给出坐标的布局上,在任何我们想要的地方放置一个按钮吗。