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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:15:40+00:00 2026-06-05T23:15:40+00:00

I have a GridView like this( main.xml ): <?xml version=1.0 encoding=utf-8?> <GridView xmlns:android=http://schemas.android.com/apk/res/android android:id=@+id/gridView1

  • 0

I have a GridView like this(main.xml):

<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/gridView1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:columnWidth="100dp"
    android:gravity="center"
    android:numColumns="2"
    android:stretchMode="columnWidth"
    android:background="@color/black"
    android:horizontalSpacing="5dp"
    android:verticalSpacing="5dp" >

</GridView>

and the GridView item like this(grid.xml):

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/gridItemLayout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="5dp"
    android:gravity="center"
    android:background="@color/white" >

    <ImageView
        android:id="@+id/grid_item_image"
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:layout_marginRight="10dp"
        android:src="@drawable/person" >
    </ImageView>

    <TextView
        android:id="@+id/grid_item_label"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/grid_item_image"
        android:text="@+id/label"
        android:layout_alignLeft="@id/grid_item_image"
        android:layout_alignRight="@id/grid_item_image"
        android:layout_marginTop="5dp"
        android:textSize="15dp"
        android:gravity="center"
        android:textColor="@color/black" >
    </TextView>

</RelativeLayout>

As I have only 2 rows of items in the GridView, I want the two rows to fill the screen exactly, not leaving any empty space or not going beyond the screen height, which needs a scroll to see fully. To do this I have done this(GridViewActivity.java):

DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);

width = metrics.widthPixels;
height = metrics.heightPixels;

and in my adapter(ImageAdapter.java):

gridView = new View(context);

gridView = inflater.inflate(R.layout.grid, null);
gridView.setMinimumHeight(GridViewActivity.height/2);
gridView.setMinimumWidth(GridViewActivity.width/2);

This doesn’t give what I want:

enter image description here

you can see the 2nd row is not completely visible

enter image description here

Can anyone help me how to make these 2 rows fit exactly in the screen, or how to make the GridView display its center when the activity is called , just like this:

enter image description here

  • 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-05T23:15:41+00:00Added an answer on June 5, 2026 at 11:15 pm

    First of all, if your GridView only has 2 rows and 2 columns and you don’t plan to add more items, why don’t you use instead a simple RelativeLayout(and a FrameLayout for each cell) to place those items in a grid like you want(or you could use a TableLayout with 2 rows)? It would be much easier to properly position them and the performance will be the same.

    If you still want to use the GridView then you would have to find the dimensions of the screen(like you already did) substract from that the space between the rows, the title bar height and the notification bar height and then divide this to your 2 rows. Then you would use this size that you previously calculated to set it as the height for the LayoutParams of the inflated item layout in the getView method of your adapter(don’t forget the width).

    My advice would be to use another layout then the GridView. Example below(you could use an include to make it smaller)

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    
        <View
            android:id="@+id/anchor"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_centerInParent="true" />
    
        <RelativeLayout
            android:id="@+id/griditem1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@id/anchor"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:layout_margin="3dp"
            android:layout_toLeftOf="@id/anchor"
            android:background="#ffffff"
            android:gravity="center"
            android:padding="5dp" >
    
            <ImageView
                android:id="@+id/grid_item_image1"
                android:layout_width="60dp"
                android:layout_height="60dp"
                android:layout_marginRight="10dp"
                android:src="@drawable/shop_open" >
            </ImageView>
    
            <TextView
                android:id="@+id/grid_item_label1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignLeft="@id/grid_item_image"
                android:layout_alignRight="@id/grid_item_image"
                android:layout_below="@id/grid_item_image"
                android:layout_marginTop="5dp"
                android:gravity="center"
                android:text="@+id/label"
                android:textColor="#000000"
                android:textSize="15dp" >
            </TextView>
        </RelativeLayout>
    
        <RelativeLayout
            android:id="@+id/griditem2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@id/anchor"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:layout_margin="3dp"
            android:layout_toRightOf="@id/anchor"
            android:background="#ffffff"
            android:gravity="center"
            android:padding="5dp" >
    
            <ImageView
                android:id="@+id/grid_item_image2"
                android:layout_width="60dp"
                android:layout_height="60dp"
                android:layout_marginRight="10dp"
                android:src="@drawable/shop_open" >
            </ImageView>
    
            <TextView
                android:id="@+id/grid_item_label2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignLeft="@id/grid_item_image"
                android:layout_alignRight="@id/grid_item_image"
                android:layout_below="@id/grid_item_image"
                android:layout_marginTop="5dp"
                android:gravity="center"
                android:text="@+id/label"
                android:textColor="#000000"
                android:textSize="15dp" >
            </TextView>
        </RelativeLayout>
    
          <RelativeLayout
            android:id="@+id/griditem3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/anchor"
            android:layout_alignParentLeft="true"
            android:layout_alignParentBottom="true"
            android:layout_margin="3dp"
            android:layout_toLeftOf="@id/anchor"
            android:background="#ffffff"
            android:gravity="center"
            android:padding="5dp" >
    
            <ImageView
                android:id="@+id/grid_item_image3"
                android:layout_width="60dp"
                android:layout_height="60dp"
                android:layout_marginRight="10dp"
                android:src="@drawable/shop_open" >
            </ImageView>
    
            <TextView
                android:id="@+id/grid_item_label3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignLeft="@id/grid_item_image"
                android:layout_alignRight="@id/grid_item_image"
                android:layout_below="@id/grid_item_image"
                android:layout_marginTop="5dp"
                android:gravity="center"
                android:text="@+id/label"
                android:textColor="#000000"
                android:textSize="15dp" >
            </TextView>
        </RelativeLayout>
    
    
          <RelativeLayout
            android:id="@+id/griditem4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/anchor"
            android:layout_alignParentRight="true"
            android:layout_alignParentBottom="true"
            android:layout_margin="3dp"
            android:layout_toRightOf="@id/anchor"
            android:background="#ffffff"
            android:gravity="center"
            android:padding="5dp" >
    
            <ImageView
                android:id="@+id/grid_item_image4"
                android:layout_width="60dp"
                android:layout_height="60dp"
                android:layout_marginRight="10dp"
                android:src="@drawable/shop_open" >
            </ImageView>
    
            <TextView
                android:id="@+id/grid_item_label4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignLeft="@id/grid_item_image"
                android:layout_alignRight="@id/grid_item_image"
                android:layout_below="@id/grid_item_image"
                android:layout_marginTop="5dp"
                android:gravity="center"
                android:text="@+id/label"
                android:textColor="#000000"
                android:textSize="15dp" >
            </TextView>
        </RelativeLayout>
    </RelativeLayout>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have followed GridView in my ASP.Net Page: http://s2.imgimg.de/uploads/14b706b38JPG.jpg It should look like this:
hi I have this gridview like this. <asp:DropDownList ID=triggerDropDown runat=server AutoPostBack=true onselectedindexchanged=triggerDropDown_SelectedIndexChanged> <asp:GridView ID=myGridView
I have a GridView what I fill through a LINQ expression. Something like this:
I have my <asp:GridView ID=gridView runat=server> I bind it like this : myConnection.Open(); SqlCommand
I have a GridView, radGvA133s, on my main form, MainForm. I would like to
I have gridview in my asp.net 3.5 application [C#]. Which looks like this: <asp:GridView
I have a gridview were I define some columns, like this... <GridViewColumn.CellTemplate> <DataTemplate> <TextBlock
Ok so I have a GridView like this: <asp:GridView ID=gv runat=server ... > ...
i have a gridview table like this... <div> <asp:GridView ID=GridView1 runat=server AllowSorting=true OnSorting=TaskGridView_Sorting >
I have a GridView control setup like this: <asp:GridView ID=UserList AllowPaging=True PageSize=20 runat=server> ...

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.