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

  • SEARCH
  • Home
  • 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 7853539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:43:44+00:00 2026-06-02T19:43:44+00:00

I am currently implementing a GridView which is connected to a custom adapter which

  • 0

I am currently implementing a GridView which is connected to a custom adapter which holds an arbitrary amount of elements.

Each of those elements is then shown in a custom ViewGroup consisting of a vertical LinearLayout with an ImageView and two TextViews. I am calculating the width of the ViewGroup based on the available screen estate and want to center it horizontally and vertically inside the grid. The problem is that the items are shown at the very left border of the screen (without any padding) and at the very right border of the screen (also without any padding). If I set a padding or margin to the entire GridView the scrollbars will be at the side of the items instead of at the border of the screen which looks awful. Thats why I don’t want to set a padding to the GridView but center the elements in it.

Here is my code for the GridView:

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

   <LinearLayout 
      android:orientation="vertical"
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent">

      <com.markupartist.android.widget.ActionBar
          android:id="@+id/actionbar"
          style="@style/ActionBar"
        />

     <GridView
           android:id="@+id/grid"
           android:layout_width="fill_parent"
           android:layout_height="wrap_content"
        android:verticalSpacing="@dimen/launch_grid_padding"
        android:horizontalSpacing="@dimen/launch_grid_padding"
           android:numColumns="auto_fit"
           android:stretchMode="columnWidth"
           android:gravity="center"
           android:listSelector="#00000000"
           android:layout_marginTop="@dimen/launch_grid_padding"
           android:layout_marginBottom="@dimen/launch_grid_padding"
     />
   </LinearLayout>

</RelativeLayout>

@dimen/launch_grid_padding has a value of 20dp.

And this is the layout for my custom ViewGroup:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:background="@drawable/rounded_box"
    android:layout_gravity="center"
>
  <ImageView 
      android:id="@+id/img"
      android:layout_width="120dp"
      android:layout_height="84dp"
      android:scaleType="centerInside"
  />
  <TextView
       android:id="@+id/identifier1"
       android:layout_width="120dp"
       android:layout_height="wrap_content"
       android:background="@android:color/white"
       android:gravity="left|center_vertical"
       android:typeface="sans"
       android:textStyle="bold" 
       android:textColor="#333333"
       android:textSize="12dp"
       android:lines="1"
       android:ellipsize="marquee"
  />
  <TextView
       android:id="@+id/identifier2"
       android:layout_width="120dp"
       android:layout_height="wrap_content"
       android:textColor="#333333"
       android:background="@android:color/white"
       android:gravity="left|center_vertical"
       android:textSize="10dp"
       android:lines="1"
  />
</LinearLayout>

This is more or less what I am trying to accomplish (with a variable amount of items):

http://www.appdesignvault.com/wp-content/uploads/2012/04/iphone-app-design-bizapp-5.jpg

Any help would be greatly appreciated!

  • 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-06-02T19:43:45+00:00Added an answer on June 2, 2026 at 7:43 pm

    specify android:columnWidth and set android:stretchMode="spacingWidthUniform" and get rid of android:horizontalSpacing and android:verticalSpacing. I hope that will solve the problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently implementing S3 integration into my Rais application which uses Paperclip. Currently,
I'm currently implementing some code that should, for each method of a class, run
I'm currently implementing a UIActionsheet that has two buttons. Each of the buttons save
I'm currently implementing some custom exceptions in a project and can't decide wither to
We are in the process of implementing a CMS for our project which currently
I am currently implementing a blog-like site using Ruby on Rails. Each Post has
I am currently implementing SiteMinder for the site, which looks for a key called
I am currently implementing a multithreaded proxy server in java which will accept messages
Currently implementing vectorial interface elements on iOS is very peculiar, UIImage advertises support only
I'm currently implementing a custom MultiPageEditorPart where I want to have multiple pages when

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.