【发布时间】:2021-12-17 13:13:21
【问题描述】:
我想在单行中显示多个芯片,可能两个或更多,并在后续行中显示。请看附件图片,我想要和图片中显示的一样。enter image description here
【问题讨论】:
标签: java android tags android-design-library android-chips
我想在单行中显示多个芯片,可能两个或更多,并在后续行中显示。请看附件图片,我想要和图片中显示的一样。enter image description here
【问题讨论】:
标签: java android tags android-design-library android-chips
将 FlexboxLayoutManager 与 RecyclerView 一起使用。
val layoutManager = FlexboxLayoutManager(this)
layoutManager.flexDirection = FlexDirection.ROW
layoutManager.flexWrap = FlexWrap.WRAP
binding.rvFilterItem.layoutManager = layoutManager
binding.rvFilterItem.adapter = tagAdapter
【讨论】:
如果要在单行中显示多个芯片,两个或多个芯片并在后续行中显示,请使用带有 Recyclerview 的 FlexboxLayoutManager。
public class YourActivity extends AppCompatActivity {RecyclerView recyclerView;ArrayList<String> arrayList = new ArrayList<>();CustomAdapter adapter; @Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);recyclerView = findViewById(R.id.recyclerView);favArray();FlexboxLayoutManager layoutManager = new FlexboxLayoutManager(this);layoutManager.setFlexDirection(FlexDirection.ROW);layoutManager.setJustifyContent(JustifyContent.CENTER);layoutManager.setAlignItems(AlignItems.CENTER);recyclerView.setLayoutManager(layoutManager);adapter = new CustomAdapter(YourActivity.this, arrayList);
@ 987654337@}private void favArray() {arrayList.add("The dark knight");arrayList.add("The god father");arrayList.add("12 Angry Man");arrayList.add("Fight club");arrayList.add("Star Wars");arrayList.add("The god father : Part 2"); arrayList.add("The dark knight");arrayList.add("The god father");arrayList.add("The god father : Part 2");}}
【讨论】: