0

我正在将 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).

我究竟做错了什么?

4

1 回答 1

2

您可以参考这些以获得帮助:

Android Flexbox setFlexBasisPercent 不起作用

或者

https://github.com/google/flexbox-layout/issues/506

于 2020-03-13T10:37:11.897 回答