gpt4 book ai didi

android - Flexboxlayout 项目之间的间距以编程方式

转载 作者:行者123 更新时间:2023-12-04 23:55:20 24 4
gpt4 key购买 nike

我有这个 Flexboxlayout 定义(official Google library):

<com.google.android.flexbox.FlexboxLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:dividerDrawableHorizontal="@drawable/flexboxlayout_divider"
app:flexWrap="wrap"
app:justifyContent="space_between"
app:showDividerHorizontal="middle">

现在我想以编程方式创建相同的内容:

FlexboxLayoutManager flexboxLayoutManager = new FlexboxLayoutManager(activity);
flexboxLayoutManager.setFlexDirection(FlexDirection.COLUMN);
flexboxLayoutManager.setJustifyContent(JustifyContent.SPACE_BETWEEN);
flexboxLayoutManager.setFlexWrap(FlexWrap.WRAP);
myRecyclerView.setLayoutManager(flexboxLayoutManager);

我缺少的是 app:dividerDrawableHorizo​​ntalapp:showDividerHorizo​​ntal 属性,但没有找到任何方法来设置它们。

最佳答案

因为它从 RecyclerView.LayoutManagerRecyclerView.ItemDecoration 扩展而来

你可以这样做


FlexboxItemDecoration itemDecoration = new FlexboxItemDecoration(context);
itemDecoration.setOrientation(FlexboxItemDecoration.HORIZONTAL); // or VERTICAL or BOTH
itemDecoration.setDrawable(drawable); // replace with actual drawable
myRecyclerView.addItemDecoration(itemDecoration);

关于android - Flexboxlayout 项目之间的间距以编程方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60212853/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com