Reducing space between list items in RecyclerView
I have a working RecyclerView inside a Fragment, but for some reason there is a lot of space in between list items, as seen below:

How can I reduce this space between the list items?
List view item XML:
https://gist.github.com/GauthamRajesh/f46b77eaa04ce26664bfb990d8334437
Fragment java code (where the RecyclerView is used):
https://gist.github.com/GauthamRajesh/7dce43ff4d31572f4603df6ef20be769
Fragment XML:
https://gist.github.com/GauthamRajesh/7eefa04684b00e4b785a3371f4d60389
I have looked at all of the other questions that have similar topics, and I have tried those solutions, but they don't change the spacing.
Thanks for helping!
add a comment |
I have a working RecyclerView inside a Fragment, but for some reason there is a lot of space in between list items, as seen below:

How can I reduce this space between the list items?
List view item XML:
https://gist.github.com/GauthamRajesh/f46b77eaa04ce26664bfb990d8334437
Fragment java code (where the RecyclerView is used):
https://gist.github.com/GauthamRajesh/7dce43ff4d31572f4603df6ef20be769
Fragment XML:
https://gist.github.com/GauthamRajesh/7eefa04684b00e4b785a3371f4d60389
I have looked at all of the other questions that have similar topics, and I have tried those solutions, but they don't change the spacing.
Thanks for helping!
1
You have 2android:layout_height="match_parent"that should bewrap_content
– TWL
Nov 12 '18 at 20:05
add a comment |
I have a working RecyclerView inside a Fragment, but for some reason there is a lot of space in between list items, as seen below:

How can I reduce this space between the list items?
List view item XML:
https://gist.github.com/GauthamRajesh/f46b77eaa04ce26664bfb990d8334437
Fragment java code (where the RecyclerView is used):
https://gist.github.com/GauthamRajesh/7dce43ff4d31572f4603df6ef20be769
Fragment XML:
https://gist.github.com/GauthamRajesh/7eefa04684b00e4b785a3371f4d60389
I have looked at all of the other questions that have similar topics, and I have tried those solutions, but they don't change the spacing.
Thanks for helping!
I have a working RecyclerView inside a Fragment, but for some reason there is a lot of space in between list items, as seen below:

How can I reduce this space between the list items?
List view item XML:
https://gist.github.com/GauthamRajesh/f46b77eaa04ce26664bfb990d8334437
Fragment java code (where the RecyclerView is used):
https://gist.github.com/GauthamRajesh/7dce43ff4d31572f4603df6ef20be769
Fragment XML:
https://gist.github.com/GauthamRajesh/7eefa04684b00e4b785a3371f4d60389
I have looked at all of the other questions that have similar topics, and I have tried those solutions, but they don't change the spacing.
Thanks for helping!
asked Nov 12 '18 at 19:55
Gautham RajeshGautham Rajesh
388
388
1
You have 2android:layout_height="match_parent"that should bewrap_content
– TWL
Nov 12 '18 at 20:05
add a comment |
1
You have 2android:layout_height="match_parent"that should bewrap_content
– TWL
Nov 12 '18 at 20:05
1
1
You have 2
android:layout_height="match_parent" that should be wrap_content– TWL
Nov 12 '18 at 20:05
You have 2
android:layout_height="match_parent" that should be wrap_content– TWL
Nov 12 '18 at 20:05
add a comment |
2 Answers
2
active
oldest
votes
You should use match_parent for your item view width, and wrap_content for your item view height. This will need to be applied to all three container views nested in your item view. So change this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
...>
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
...>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
...>
<TextView .../>
<TextView .../>
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
to this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
...>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
...>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView .../>
<TextView .../>
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
It works like a charm. Thanks!!
– Gautham Rajesh
Nov 12 '18 at 20:45
add a comment |
you need to just change in the layout height of the listview that will be android:layout_height="wrap_content "and in Linear layout also as you shown in your code.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53269213%2freducing-space-between-list-items-in-recyclerview%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You should use match_parent for your item view width, and wrap_content for your item view height. This will need to be applied to all three container views nested in your item view. So change this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
...>
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
...>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
...>
<TextView .../>
<TextView .../>
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
to this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
...>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
...>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView .../>
<TextView .../>
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
It works like a charm. Thanks!!
– Gautham Rajesh
Nov 12 '18 at 20:45
add a comment |
You should use match_parent for your item view width, and wrap_content for your item view height. This will need to be applied to all three container views nested in your item view. So change this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
...>
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
...>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
...>
<TextView .../>
<TextView .../>
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
to this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
...>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
...>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView .../>
<TextView .../>
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
It works like a charm. Thanks!!
– Gautham Rajesh
Nov 12 '18 at 20:45
add a comment |
You should use match_parent for your item view width, and wrap_content for your item view height. This will need to be applied to all three container views nested in your item view. So change this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
...>
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
...>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
...>
<TextView .../>
<TextView .../>
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
to this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
...>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
...>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView .../>
<TextView .../>
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
You should use match_parent for your item view width, and wrap_content for your item view height. This will need to be applied to all three container views nested in your item view. So change this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
...>
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
...>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
...>
<TextView .../>
<TextView .../>
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
to this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
...>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
...>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView .../>
<TextView .../>
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
answered Nov 12 '18 at 20:28
Ben P.Ben P.
23.6k32049
23.6k32049
It works like a charm. Thanks!!
– Gautham Rajesh
Nov 12 '18 at 20:45
add a comment |
It works like a charm. Thanks!!
– Gautham Rajesh
Nov 12 '18 at 20:45
It works like a charm. Thanks!!
– Gautham Rajesh
Nov 12 '18 at 20:45
It works like a charm. Thanks!!
– Gautham Rajesh
Nov 12 '18 at 20:45
add a comment |
you need to just change in the layout height of the listview that will be android:layout_height="wrap_content "and in Linear layout also as you shown in your code.
add a comment |
you need to just change in the layout height of the listview that will be android:layout_height="wrap_content "and in Linear layout also as you shown in your code.
add a comment |
you need to just change in the layout height of the listview that will be android:layout_height="wrap_content "and in Linear layout also as you shown in your code.
you need to just change in the layout height of the listview that will be android:layout_height="wrap_content "and in Linear layout also as you shown in your code.
answered Nov 12 '18 at 20:17
Vishal SharmaVishal Sharma
1
1
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53269213%2freducing-space-between-list-items-in-recyclerview%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
You have 2
android:layout_height="match_parent"that should bewrap_content– TWL
Nov 12 '18 at 20:05