【问题标题】:Large gap between RecyclerView itemsRecyclerView 项目之间的差距很大
【发布时间】:2016-09-13 18:19:30
【问题描述】:

在我运行我的应用程序后,我发现 RecyclerView 项目之间的差距很大! 这是我的代码:Github Large gap between recyclerview items

【问题讨论】:

标签: android xml android-recyclerview


【解决方案1】:

像这样改变你的布局

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.breuhteam.recyclerview.MainActivity">

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

view_item.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="wrap_content">

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/itemView"
    android:src="@drawable/diy"
    android:layout_margin="1dp"
    android:adjustViewBounds="true"/>
</RelativeLayout>

【讨论】:

  • 感谢它对我有用,但是当我向下滑动并且我想回到向上的项目时,一些项目大小会发生变化
  • 因为recyclerview每次创建新视图,都需要为你的物品设置标签。
  • 请问我该怎么做!!?
  • 这个答案对我有用,谢谢@UttamPanchasara。