解决recyclerview 第一次加载固定的item 不显示的问题

阅读 55

2023-03-08


这个问题的原因是

item的布局没有设置具体宽高,先指定宽高,如果还要再计算宽高可以在onbindView中再计算设置

 

ImageView img1 =  holder.findViewById(R.id.img1);
LinearLayout content= holder.findViewById(R.id.content);
int width= ((ScreenUtils.getScreenWidth(SuggestionActivity.this)-ScreenUtils.dip2px(SuggestionActivity.this,50))/4);
LinearLayout.LayoutParams layoutParams= new LinearLayout.LayoutParams(width,width);
img1.setLayoutParams(layoutParams);
content.setLayoutParams(layoutParams);

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="wrap_content"
android:id="@+id/content"
android:orientation="vertical">

<ImageView
android:id="@+id/img1"
android:layout_width="60dp"
android:layout_height="60dp"
/>


</LinearLayout>

 

精彩评论(0)

0 0 举报