如何以编程方式更改android RecyclerView子视图高度?

时间:2017-08-18 15:41:04

标签: android data-binding android-recyclerview recycler-adapter

由于内容的大小,我想以编程方式将@foreach(session('data_record') as $item) {{$item->lat}},{{$item->lng}} <br> @endforeach 项高度更改为RecyclerViewmatch_parent。如何更改子项的高度?

wrap_content

1 个答案:

答案 0 :(得分:0)

您需要在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