如果在代码中动态设置了background后padding无效,需要在setBackground后重新设置一次padding
verticalLayout {
backgroundDrawable = getShapeDrawable(ContextCompat.getColor(ctx, R.color.defaultBackground), 2f, 2, ContextCompat.getColor(ctx, R.color.gray_split), 3f, 2f)
padding=dip(15f)
textView {
text = "姓名:"
gravity = Gravity.CENTER_VERTICAL
}.lparams {
width = matchParent
height = dip(20f)
}
textView {
text = "身份证号:"
gravity = Gravity.CENTER_VERTICAL
}.lparams {
width = matchParent
height = dip(20f)
}
textView {
text = "身份证有效期:"
gravity = Gravity.CENTER_VERTICAL
}.lparams {
width = matchParent
height = dip(20f)
}
}.lparams {
gravity = Gravity.CENTER_HORIZONTAL
width = dip(300f)
height = wrapContent
bottomMargin=dip(20f)
}

本文介绍在代码中动态设置背景后遇到的padding无效问题,并提供了解决方案。通过在设置完背景后重新设置padding,可以确保布局正确显示。
3872

被折叠的 条评论
为什么被折叠?



