RecyclerView嵌套ScrollView 冲突解决

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xueshao110/article/details/89386206

问题,在ScrollView中嵌套RecyclerView高度问题显示不全;

解决办法

1 把RecyclerView高度写死(不推荐)

2 动态计算

步骤

在adapter里边计算出条目总数x条目高度 在onBindViewHolder 方法中调用

//创建方法计算高度
public void setHeight(){
      if(is||recy==null){
          return;
      }
    //表示只计算一次
    is=true;
    RecyclerView.LayoutParams items=(RecyclerView.LayoutParams)inflate.getLayoutParams();
    //条目高度
    int itemCount = getItemCount();
   int heights=itemCount*items.height;
    LinearLayout.LayoutParams rl=(LinearLayout.LayoutParams)recy.getLayoutParams();
    rl.height= heights;
    recy.setLayoutParams(rl);

   

猜你喜欢

转载自blog.csdn.net/xueshao110/article/details/89386206