Recycler View 不能与 ImageView 一起使用,但可以与 ImageView

今天,我正在与最疯狂的问题之一作斗争,这让我发疯。在我的 RecyclerView 项目 xml 中,如果我只有 imageView,那么什么都不会显示,并且列表是空白的,但是如果我在该 ImageView 下方添加 TextView,那么 ImageView 和 TextView 都可以正常工作。发生了什么,请帮忙。


item_row.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="match_parent"

    android:layout_height="wrap_content">


    <ImageView

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:id="@+id/saved_post_imageview"/>


    <!--<TextView-->

        <!--android:layout_width="wrap_content"-->

        <!--android:layout_height="wrap_content"-->

        <!--android:id="@+id/text"/>-->


</RelativeLayout>

ProfileActivity.java

public class ProfileActivity extends AppCompatActivity {


FirebaseAuth mFirebaseAuth;

TextView usernameTxt;

ImageView displayPicImg;

RecyclerView recyclerView;

FirebaseDatabase mFirebaseDatabase;

DatabaseReference mUsersReference;

ArrayList<String> mPostList;

SavedPostsAdapter savedPostsAdapter;


@Override

protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_profile_activity);


}


杨魅力
浏览 127回答 2
2回答

千巷猫影

ImageView为您的前任提供默认高度和宽度值:<ImageView &nbsp;android:layout_width="20dp" &nbsp;android:layout_height="20dp" &nbsp;android:id="@+id/imageview"/>或者为您提供默认的静态图片ImageView我相信您的代码实际上是有效的,只是大小没有RecyclerView正确设置。RecyclerView回收已经创建的视图,因为您ImageView没有将其缓存为每行大小的尺寸,这会导致您Glide在那些小的或不可见的行上加载图像。此外,您还可以利用Glide的尺寸调整功能将其放入所需的容器中,如下所示:Glide &nbsp;&nbsp;&nbsp;&nbsp;.with(context) &nbsp;&nbsp;&nbsp;&nbsp;.load(path) &nbsp;&nbsp;&nbsp;&nbsp;.apply(new&nbsp;RequestOptions().override(100,&nbsp;100)) &nbsp;&nbsp;&nbsp;&nbsp;.into(imageView);

噜噜哒

尝试在 item_row.xml 中添加 ViewGroup<LinearLayout &nbsp;&nbsp;&nbsp;&nbsp;android:layout_width="match_parent" &nbsp;&nbsp;&nbsp;&nbsp;android:layout_height="50dp"&nbsp;//&nbsp;or&nbsp;wrap_content&nbsp;> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<ImageView/></LinearLayout>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java