Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6792551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:59:02+00:00 2026-05-26T17:59:02+00:00

This thing has been doing my head in for a little while now and

  • 0

This thing has been doing my head in for a little while now and I can’t seem to be able to solve it.

I’ve got a grid view, in which I display a few bitmaps. I add a padding of 5dp on all image sides when filling up my image view via the adapter (iv.setPadding(5, 5, 5, 5);), but somehow, there’s more space being added to the top and bottom on each item on my gridview.

I know this has already been asked a few times here, and some of them even have accepted answers, however, when I try to sue the answers as described on the URL’s above, I still keep getting the same extra spaces on top and bottom.

Is there any other way of doing this nowadays?

Here’s some of my code:

Main.xml

<?xml version="1.0" encoding="utf-8"?>
<GridView
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/imageGrid"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:numColumns="6"
    />

grid_item.xml

<?xml version="1.0" encoding="utf-8"?>
<ImageView 
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:id="@+id/grid_item_image"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content" />

I have tried adding the following to my listselector attribute in main.xml

  • @null
  • @drawable/solid_white
  • @android:id/empty

Here’s how it looks like with the extra spaces on top and bottom (the ones on the sides are the ones I’m adding as described above):

enter image description here

Any other ideas as to how to get those bloody spaces removed so my grid view has the same spacing?

Thanks in advance,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T17:59:03+00:00Added an answer on May 26, 2026 at 5:59 pm

    If not otherwise set, a GridView will override the layout you’re imagining it should produce by stretching things in various ways. If you want to have full control of the layout by defining the column widths and the size of the grid items, then you have to make sure to set the GridView’s stretchMode property to “none”.

    <GridView
            ...
            android:stretchMode="none">
    </GridView>
    

    Also, you are filling the parent with your GridView width. I think you should be wrapping the content for the width unless you want extra filling added. Where are you adding the 5dp padding? Around each bitmap or around the edge of the gridview? I don’t see it.

    You should probably be filling the height though.
    (in the following some of the width and heights can probably be replaced by “wrap_content”)

    So, for you

    <?xml version="1.0" encoding="utf-8"?>
    <GridView
        xmlns:android="http://schemas.android.com/apk/res/android" 
        android:id="@+id/imageGrid"
        android:stretchMode="none"        
        android:layout_width="XXXdp"
        android:layout_height="fill_content"
        android:numColumns="6"
        />
    

    Also, not sure if you need column spacing and width, which would be something like (or a dp instead of wrap_content) – you may not need these in your GridView – I’m not sure:

        android:columnWidth="YYYdp"
        android:horizontalSpacing="0dp"
    

    ImageViews with 5dp padding:

    <?xml version="1.0" encoding="utf-8"?>
    <ImageView 
       xmlns:android="http://schemas.android.com/apk/res/android"
       android:id="@+id/grid_item_image"
       android:padding="5dp"
       android:layout_width="UUUdp"
       android:layout_height="VVVdp" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this problem has been doing my head in and I hope you can help!
I've been having this really annoying thing happen the past few days, that has
I was doing some stuff with palindromes: This number 9966006699 has been giving me
I've got a repository i've been working with a little, it has around 805
This question has been on my mind for a while. I used C++ for
I have been struggling with this thing for a while so I finally decided
I don't think this question has been asked before. I'm a bit confused on
I'm hoping this question has a very simple answer. I can think of ways
I've been banging my head with this all day, trying anything and everything I
This has been bothering me for quite some time. I'm simply trying to change

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.