【问题标题】:When Scrolling in RecyclerView automatically adds space in between rows在 RecyclerView 中滚动时自动在行之间添加空间
【发布时间】:2016-07-22 06:02:28
【问题描述】:

我使用 RecyclerView 使用 Volley Library 显示一些 JSON 数据。我正在获取 JSON 数据,但最初显示数据时,它的格式正确。但是当我在 recyclerview 中滚动时,行之间会增加巨大的空间。

滚动前

滚动后 这是 row.xml 的 XML 部分

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
    android:id="@+id/tv_title"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@+id/iv_image"
    android:textSize="18sp"
    />
</RelativeLayout>

这里是xml中添加的recyclerview

 <android.support.v7.widget.RecyclerView
    android:id="@+id/recycler_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"

    />
</android.support.design.widget.CoordinatorLayout>

提前致谢。

【问题讨论】:

    标签: android json scroll android-recyclerview


    【解决方案1】:

    将相对布局的高度更改为 row.xml 中的 wrap_content

      android:layout_height="wrap_content "
    

    【讨论】:

    • 谢谢,但为什么它最初显示时没有任何空格??
    • 我不知道,从逻辑上讲它不应该这样显示。
    • 我还有其他问题
    • 你有什么问题?
    • placehold.it/600/92c952 这是 json 数据中图像的链接,但是当我尝试在 image_view 中使用此链接显示时,它没有显示任何内容。
    【解决方案2】:

    但为什么它最初显示时没有任何空格?

    ListView 和 RecycleView 都有默认的视图高度。 您使用 match_parent 然后它将使用默认高度,因此由于上方显示空白。

    如果您的 TextView 重力将是垂直中心,那么它将在顶部和底部都显示空间。

    【讨论】:

      猜你喜欢
      • 2016-11-08
      • 2016-08-12
      • 2016-09-09
      • 1970-01-01
      • 1970-01-01
      • 2020-12-05
      • 1970-01-01
      • 2021-01-31
      • 2018-06-15
      相关资源
      最近更新 更多