我想将paddingTop放在verticalLayout
上,但是会提示警告
Val无法重新分配。我认为我以错误的方式解决了这个问题,但是在线资源似乎很稀缺。
以下是我的AnkoComponent:
class MainActivityUi : AnkoComponent<MainActivity> {
override fun createView(ui: AnkoContext<MainActivity>) = with(ui) {
verticalLayout {
textView {
text = "Input"
textColor = Color.BLACK
textAlignment = View.TEXT_ALIGNMENT_CENTER
}
textView {
text = "Output"
textColor = Color.BLACK
textAlignment = View.TEXT_ALIGNMENT_CENTER
}
linearLayout {
button {
text = "0"
}.lparams(width = wrapContent, height = matchParent) {
gravity = Gravity.CENTER
weight = 5f
margin = dip(3)
}
button {
text = "1"
}.lparams(width = wrapContent, height = matchParent) {
gravity = Gravity.CENTER
weight = 5f
margin = dip(3)
}
}
linearLayout {
button {
text = "/"
}.lparams(width = wrapContent, height = matchParent) {
gravity = Gravity.CENTER
weight = 5f
margin = dip(3)
}
button {
text = "*"
}.lparams(width = wrapContent, height = matchParent) {
gravity = Gravity.CENTER
weight = 2.5f
margin = dip(3)
}
button {
text = "-"
}.lparams(width = wrapContent, height = matchParent) {
gravity = Gravity.CENTER
weight = 2.5f
margin = dip(3)
}
button {
text = "+"
}.lparams(width = wrapContent, height = matchParent) {
gravity = Gravity.CENTER
weight = 2.5f
margin = dip(3)
}
}
linearLayout {
button {
text = "base10"
}.lparams(width = matchParent, height = wrapContent){
margin = dip(3)
}
}
linearLayout {
button {
text = "calculate!"
}.lparams(width = matchParent, height = wrapContent){
margin = dip(3)
}
}
lparams { //This is the culprit!
paddingTop = dip(200)
}
}
}
marginTop
或paddingTop
都不起作用,但是IDE在键入margin
或padding
时建议使用。只是padding
或margin
不会提示错误,但是我只在组件的顶部寻找空间。 最佳答案
使用topPadding
代替paddingTop
关于android - ANKO paddingTop-无法重新分配Val,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54863033/