【问题标题】:Different height in ConstraintLayout RecyclerViewConstraintLayout RecyclerView中的不同高度
【发布时间】:2021-02-26 20:10:52
【问题描述】:

我有这个结构

RecyclerView
 - ConstraintLayout
 - - CardView
 - - - ConstraintLayout
 - - - - ImageView 
 - - - - TextView
 - - - - TextView

代码:

    vm = ViewModelProvider(this)[CatalogViewModel::class.java]
    vm.getList().observe(this, Observer {
        dataView = findViewById(R.id.dataList)
        adapter = CatalogRecycleViewAdapter(this, it.data.data)

        dataView.layoutManager = GridLayoutManager(this, 2, GridLayoutManager.VERTICAL, false);
        dataView.adapter = adapter;
    })

如果我有 2 个或更多宽度不同高度的项目,则一列中有一个空白区域。

如何将其移除并制作成图片中的样子?

【问题讨论】:

    标签: android android-layout kotlin android-recyclerview


    【解决方案1】:

    您的 TextView 似乎具有 wrap_content 高度,这就是一个更大的原因。查看此答案以获得您正在寻找的结果StaggeredGridLayoutManager

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-05
      • 1970-01-01
      • 1970-01-01
      • 2018-01-05
      • 1970-01-01
      相关资源
      最近更新 更多