after I run my application I get large gap between RecyclerView items !! this is my code here : Github Large gap between recyclerview items
Asked
Active
Viewed 5,236 times
3
-
Share your xml file – Uttam Panchasara Sep 13 '16 at 18:23
-
you can see it here https://github.com/userRidae/RecyclerView/tree/master/app/src/main/res/layout – Ridae HAMDANI Sep 13 '16 at 18:26
2 Answers
11
Change your Layouts like this
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>

Uttam Panchasara
- 5,735
- 5
- 25
- 41
-
thanks it work for me but when I scoll down and I want to go back to up item some item size change – Ridae HAMDANI Sep 13 '16 at 18:42
-
it's because of recyclerview every time create the new view, you have to setTag for your items. – Uttam Panchasara Sep 13 '16 at 18:44
-
-
example : http://stackoverflow.com/questions/26889361/getting-a-reference-to-viewholder-on-recyclerview-click – Uttam Panchasara Sep 13 '16 at 18:50
-
-
The layout_margin and adjustViewBounds properties are important and not mentioned by most answers. – Michele Dorigatti Aug 02 '20 at 16:20
0
So I had the same problem but with text but I think it doesnt matter
We need to change the height of the constraint layout to wrap content instead match parent enter image description here

Matrix Gaming
- 3
- 1
-
As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – hossein Jul 27 '23 at 10:57