Reducing space between list items in RecyclerView










0















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!










share|improve this question

















  • 1





    You have 2 android:layout_height="match_parent" that should be wrap_content

    – TWL
    Nov 12 '18 at 20:05















0















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!










share|improve this question

















  • 1





    You have 2 android:layout_height="match_parent" that should be wrap_content

    – TWL
    Nov 12 '18 at 20:05













0












0








0








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!










share|improve this question














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!







android android-recyclerview






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 12 '18 at 19:55









Gautham RajeshGautham Rajesh

388




388







  • 1





    You have 2 android:layout_height="match_parent" that should be wrap_content

    – TWL
    Nov 12 '18 at 20:05












  • 1





    You have 2 android:layout_height="match_parent" that should be wrap_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












2 Answers
2






active

oldest

votes


















1














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>





share|improve this answer























  • It works like a charm. Thanks!!

    – Gautham Rajesh
    Nov 12 '18 at 20:45


















-1














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. 





share|improve this answer






















    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
    );



    );













    draft saved

    draft discarded


















    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









    1














    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>





    share|improve this answer























    • It works like a charm. Thanks!!

      – Gautham Rajesh
      Nov 12 '18 at 20:45















    1














    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>





    share|improve this answer























    • It works like a charm. Thanks!!

      – Gautham Rajesh
      Nov 12 '18 at 20:45













    1












    1








    1







    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>





    share|improve this answer













    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>






    share|improve this answer












    share|improve this answer



    share|improve this answer










    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

















    • 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













    -1














    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. 





    share|improve this answer



























      -1














      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. 





      share|improve this answer

























        -1












        -1








        -1







        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. 





        share|improve this answer













        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. 






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 12 '18 at 20:17









        Vishal SharmaVishal Sharma

        1




        1



























            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Kleinkühnau

            Makov (Slowakei)

            Peter Parker: The Spectacular Spider-Man #308