我正在将 GoogleFlexBoxLayout
用于一个项目,但我无法flexBasisPercent
为我以编程方式定义的视图工作。根视图声明为,
val root = FlexboxLayout(context)
root.layoutParams = ViewGroup.LayoutParams(FlexboxLayout.LayoutParams.WRAP_CONTENT, FlexboxLayout.LayoutParams.WRAP_CONTENT)
root.flexWrap = FlexWrap.WRAP
root.flexDirection = FlexDirection.COLUMN
root.justifyContent = JustifyContent.FLEX_START
root.alignItems = AlignItems.FLEX_START
root.alignContent = AlignContent.FLEX_START
和子视图,
val child = FlexboxLayout(context)
val childParams = FlexboxLayout.LayoutParams(FlexboxLayout.LayoutParams.WRAP_CONTENT, FlexboxLayout.LayoutParams.WRAP_CONTENT)
childParams.flexGrow = 0.5f
childParams.flexBasisPercent = 0.5f
childParams.setMargins(16,16,16,16)
child.layoutParams = childParams
val info = TextView(context)
info.layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
info.text = "12"
child.addView(info)
root.addView(child).
我究竟做错了什么?