【问题标题】:Display Multiple chips/tags in single line in android using autocomplete text view使用自动完成文本视图在 android 中单行显示多个芯片/标签
【发布时间】:2021-12-17 13:13:21
【问题描述】:

我想在单行中显示多个芯片,可能两个或更多,并在后续行中显示。请看附件图片,我想要和图片中显示的一样。enter image description here

【问题讨论】:

    标签: java android tags android-design-library android-chips


    【解决方案1】:

    将 FlexboxLayoutManager 与 RecyclerView 一起使用。

            val layoutManager = FlexboxLayoutManager(this)
            layoutManager.flexDirection = FlexDirection.ROW
            layoutManager.flexWrap = FlexWrap.WRAP
            binding.rvFilterItem.layoutManager = layoutManager
            binding.rvFilterItem.adapter = tagAdapter
    

    【讨论】:

    • 你能分享一个完整的例子吗?谢谢
    • @Himanshuverma 我没有在我的回收站视图中使用芯片。我的房车有不同的布局。请自行设计布局,在配置recycler view adapter时使用上述代码。
    【解决方案2】:

    如果要在单行中显示多个芯片,两个或多个芯片并在后续行中显示,请使用带有 Recyclerview 的 FlexboxLayoutManager。

    public class YourActivity extends AppCompatActivity {
    RecyclerView recyclerView;
    ArrayList<String> arrayList = new ArrayList<>();
    CustomAdapter adapter;
    @Override
    protected 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");
    }
    }

    【讨论】:

      猜你喜欢
      • 2017-12-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-12
      • 2011-10-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多