以编程方式设置FlexboxLayout的属性layout_wrapbefore

4
我有一个包含TextView属性的flexbox-layout

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>
1个回答

5

您必须使用setWrapBefore方法,按照其LayoutParams的描述设置这些布局参数,并将这些布局参数重新设置给TextView。

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);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接