【问题标题】:How to change android RecyclerView child view height programatically?如何以编程方式更改 android RecyclerView 子视图高度?
【发布时间】:2017-08-18 15:41:04
【问题描述】:

由于内容的大小,我想以编程方式将我的 RecyclerView 项目高度更改为 match_parentwrap_content。如何改变子项的高度?

DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(binding.RVOperation.getContext(), DividerItemDecoration.VERTICAL);
binding.RVOperation.setLayoutManager(staggeredGridLayoutManager);
binding.RVOperation.addItemDecoration(dividerItemDecoration);
Log.d("COUNTT", String.valueOf(binding.RVOperation.getAdapter().getItemCount()));

【问题讨论】:

    标签: android data-binding android-recyclerview


    【解决方案1】:

    您需要在 RecyclerView 中覆盖 onBindViewHolder 并在 viewholder 的容器上调用 setLayoutParams。

    示例:

     @Override
     public void onBindViewHolder(SimpleItemViewHolder holder, int position){
     // do whatever here
    
     // add your layout parameters here. Here I'm setting the width and height to match parent
        TableRow.LayoutParams params = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.MATCH_PARENT); //(width,height)
        holder.container.setLayoutParams(params);
     }
    

    Source

    【讨论】:

      猜你喜欢
      • 2021-04-23
      • 1970-01-01
      • 1970-01-01
      • 2022-01-14
      • 2013-08-08
      • 1970-01-01
      • 1970-01-01
      • 2014-11-21
      • 1970-01-01
      相关资源
      最近更新 更多