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 8981151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:15:43+00:00 2026-06-15T20:15:43+00:00

What’s up guys, just a quick question. I’m trying to get my GridView to

  • 0

What’s up guys, just a quick question. I’m trying to get my GridView to be center inside it’s parent which is a RelativeLayout. I want the entire grid to be centered, not the items. From what I’m seeing, the default alignment is “left-aligned” and it’s difficult to change this behavior. I tried a few other solutions suggested in other SO questions found here as well as couple others. This seems like something trivial, and that it shouldn’t be such a headache. I tried wrapping the GridView inside a LinearLayout with horizontal orientation but to no avail.

The only semi workaround I’ve found was to mess around with the left and right padding, but even that approach leaves way too much empty space at the sides.

This image is before I changed the padding
BEFORE

This image is after I messed around with padding, but again..seems a bit hackish and not really what I’m looking for. I’m looking for flush center without the extra padding on the sides

AFTER

Another reason why this approach is impractical is due to the extra space, the selector appears to be too large..as seen in the image below

enter image description here

Any help on this would great, thanks as always!

Code for the layout

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

<GridView
    android:id="@+id/menuGridView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:background="@drawable/weathermate_lv_background"
    android:gravity="center_horizontal"
    android:listSelector="@drawable/list_selector"
    android:numColumns="3"
    android:paddingLeft="30dp"
    android:paddingRight="5dp"
    android:stretchMode="columnWidth"
    android:visibility="invisible" >
</GridView>

</RelativeLayout>

EDIT

As suggest by user, I centered each grid item row inside it’s own relative layout..and that gave me the result I was looking for! Here is the updated XML files to reflect the solution

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

<GridView
    android:id="@+id/menuGridView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:background="@drawable/weathermate_lv_background"
    android:gravity="center_horizontal"
    android:listSelector="@drawable/list_selector"
    android:numColumns="3"
    android:stretchMode="columnWidth"
    android:visibility="invisible" >
</GridView>

</RelativeLayout>

This is the layout for the grid row. As you can see, what worked for me was setting the orientation to Horizontal and adding android:layout_centerHorizontal=”true” to each child.

 <?xml version="1.0" encoding="utf-8"?>

<ImageView
    android:id="@+id/menuItem"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:layout_centerHorizontal="true"
    android:background="@android:drawable/ic_menu_add" >
</ImageView>

<TextView
    android:id="@+id/tvMenuItemName"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/menuItem"
    android:layout_centerHorizontal="true"
    android:text="Option"
    android:textColor="@android:color/white" >
</TextView>

</RelativeLayout>
  • 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-15T20:15:44+00:00Added an answer on June 15, 2026 at 8:15 pm

    The answear is to center image and text views in each grids as they have separate layout 🙂

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

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to select an H1 element which is the second-child in its group
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I used javascript for loading a picture on my website depending on which small
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported

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.