以编程方式设置 FlexboxLayout 的属性 layout_wrapbefore
set FlexboxLayout's attribute layout_wrapbefore programmatically
我有 flexbox-layout
包含 TextView
具有以下属性:
app:layout_wrapBefore="true"
但我需要以编程方式将其设置为 false
!
知道怎么做吗?
xml,如果需要的话!
<com.google.android.flexbox.FlexboxLayout
android:id="@+id/flexboxlayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
app:alignContent="stretch"
app:alignItems="stretch"
app:flexWrap="wrap"
app:justifyContent="flex_end">
<TextView
android:id="@+id/mainText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="07:22 PM"
android:textSize="12sp"
app:layout_alignSelf="center"
app:layout_wrapBefore="true" />
</com.google.android.flexbox.FlexboxLayout>
您必须使用其 LayoutParams 中描述的 setWrapBefore 方法并将这些布局参数再次设置为 TextVuew。
TextView mainTextView = findViewById(R.id.mainText); // or get it as you should
FlexboxLayout.LayoutParams lp = (FlexboxLayout.LayoutParams) mainTextView.getLayoutParams();
lp.setWrapBefore(false);
mainTextView.setLayoutParams(lp);
我有 flexbox-layout
包含 TextView
具有以下属性:
app:layout_wrapBefore="true"
但我需要以编程方式将其设置为 false
!
知道怎么做吗?
xml,如果需要的话!
<com.google.android.flexbox.FlexboxLayout
android:id="@+id/flexboxlayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
app:alignContent="stretch"
app:alignItems="stretch"
app:flexWrap="wrap"
app:justifyContent="flex_end">
<TextView
android:id="@+id/mainText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="07:22 PM"
android:textSize="12sp"
app:layout_alignSelf="center"
app:layout_wrapBefore="true" />
</com.google.android.flexbox.FlexboxLayout>
您必须使用其 LayoutParams 中描述的 setWrapBefore 方法并将这些布局参数再次设置为 TextVuew。
TextView mainTextView = findViewById(R.id.mainText); // or get it as you should
FlexboxLayout.LayoutParams lp = (FlexboxLayout.LayoutParams) mainTextView.getLayoutParams();
lp.setWrapBefore(false);
mainTextView.setLayoutParams(lp);