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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:32:52+00:00 2026-06-09T14:32:52+00:00

I’m writing my first android application. I’m using android 2.3.3 SDK. the game is

  • 0

I’m writing my first android application. I’m using android 2.3.3 SDK.
the game is kind of a cards game that has a 4×4 grid of cards on the screen.

when the game starts the only thing visible on the screen is the datagrid (no menus or nothing).

so the GameActivity layout is the following:

<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/faces_grid_view"
    android:numColumns="4"
    android:verticalSpacing="1dp"
    android:horizontalSpacing="1dp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
>
</GridView>

this is the relevant code of the onCreate function of the GameActivity class:

          Display display = getWindowManager().getDefaultDisplay();
            final int width  = display.getWidth();
            final int height = display.getHeight();

            final int bottomPadding=150;
             //Display display = getWindowManager().getDefaultDisplay();
            gameTurns = new ArrayList<GameTurn>();
            imageWidth=width/4;
            imageHeight=(height-bottomPadding)/4;
            imageAdapter = new ImageAdapter(this,imageWidth,imageHeight);
            facesGridView = (GridView) findViewById(R.id.faces_grid_view);
            facesGridView.setAdapter(imageAdapter);

in the onCreate() code I’m getting the defaultDisplaySize, divide it by 4 so i’ll know the max height and width that an image can take.

  • for some reason I need to add a bottomPadding. I checked it on galaxy note and galaxy tab 10.1 and maybe the getDefaultDisplay also returns the space of the bottom toolbar of the tablet itself so the pictures overlap the all screen without any padding.

as you can see I set an adapter for the GridView. the adapter extends BaseAdapter
and i paste to his constructor the width and height the I calculated earlier.

the getView function of the adapter contains the following:

      public View getView(int position, View convertView, ViewGroup parent) {
            ImageView imageView;
            if (convertView == null) {  // if it's not recycled, initialize some attributes
                imageView = new ImageView(mContext);
                LayoutParams param = new    LinearLayout.LayoutParams(this.imageWidth,this.imageHeight);
                imageView.setLayoutParams(new GridView.LayoutParams(param));
                imageView.setAdjustViewBounds(true);
                imageView.setScaleType(ScaleType.CENTER_INSIDE);
                imageView.setPadding(1,1,1,1);
            } else {
                imageView = (ImageView) convertView;
            }

so a couple of questions:

  1. is there a way just to configure the datagrid to be visible on the all screen and to show all items with no scrolling without configuration the image width or height ? why do I need to work so hard for such a simple task?
  2. if I do need to calculate stuff myself, is there a way to get the actual Activity height and width so I won’t need to add any padding? welp I want it to work on all scree sizes in landscape and portrait.

I tired to change and play with the configuration for many days and that’s the best I’ve achieved so far so any information regarding the issue would be greatly appreciated.

update

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:stretchColumns="*"
    android:weightSum="4" >

<TableRow
    android:id="@+id/tableRow1"
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:layout_weight="1"
     >
<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:contentDescription="@string/face"
    android:onClick="onItemClick"
     />
<ImageView
    android:id="@+id/imageView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:contentDescription="@string/face"
    android:onClick="onItemClick"
     />
<ImageView
    android:id="@+id/imageView3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:contentDescription="@string/face"
    android:onClick="onItemClick"
     />
<ImageView
    android:id="@+id/imageView4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:contentDescription="@string/face"
    android:onClick="onItemClick"
     />

</TableRow>
<TableRow
    android:id="@+id/tableRow2"
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:layout_weight="1"
     >
<ImageView
    android:id="@+id/imageView5"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:contentDescription="@string/face"
    android:onClick="onItemClick"
     />
<ImageView
    android:id="@+id/imageView6"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:contentDescription="@string/face"
    android:onClick="onItemClick"
     />
<ImageView
    android:id="@+id/imageView7"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:contentDescription="@string/face"
    android:onClick="onItemClick"
     />
<ImageView
    android:id="@+id/imageView8"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:contentDescription="@string/face"
    android:onClick="onItemClick"
     />

</TableRow>
    <TableRow
    android:id="@+id/tableRow3"
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:layout_weight="1"
    >
<ImageView
    android:id="@+id/imageView9"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:contentDescription="@string/face"
    android:onClick="onItemClick"
     />
<ImageView
    android:id="@+id/imageView10"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:contentDescription="@string/face"
    android:onClick="onItemClick"
     />
<ImageView
    android:id="@+id/imageView11"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:contentDescription="@string/face"
    android:onClick="onItemClick"
     />
<ImageView
    android:id="@+id/imageView12"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:contentDescription="@string/face"
    android:onClick="onItemClick"
     />

</TableRow>
    <TableRow
    android:id="@+id/tableRow4"
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:layout_weight="1"
    >
<ImageView
    android:id="@+id/imageView13"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:contentDescription="@string/face"
    android:onClick="onItemClick"
     />
<ImageView
    android:id="@+id/imageView14"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:contentDescription="@string/face"
    android:onClick="onItemClick"
     />
<ImageView 
    android:id="@+id/imageView15"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:contentDescription="@string/face"
    android:onClick="onItemClick"
     />
<ImageView
    android:id="@+id/imageView16"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:contentDescription="@string/face"
    android:onClick="onItemClick"
     />

</TableRow>

</TableLayout>

this xml file results in a 4 images centered and spread vertically (this fits the all screen so there may be more below).

screenshot
.

what did i miss? 🙂

thanks!

Kfir

  • 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-09T14:32:53+00:00Added an answer on June 9, 2026 at 2:32 pm

    is there a way just to configure the datagrid to be visible on the all
    screen and to show all items with no scrolling without configuration
    the image width or height ? why do I need to work so hard for such a
    simple task?

    This is a simple task just that you’re using the wrong widget. You would generally use a GridView if the grid of cells is bigger than the screen so you could benefit from the GridView‘s recycling mechanism(to improve performance and to don’t get in trouble with the app’s memory). This is not your case as you want all the cells to be visible.

    I would use a TableLayout with width and height set to FILL_PARENT(with stretchColumns set to * so the row columns will have the same width) which will contain four TableRows(with layout_weight set to 1(and weighSum set to 4 for the parent TableLayout) so they will have equal height), also the layout_height for the TableRow will be set to 0dp. Each TableRow will contain four ImageViews.

    if I do need to calculate stuff myself, is there a way to get the
    actual Activity height and width so I won’t need to add any padding?
    Help I want it to work on all scree sizes in landscape and portrait.

    I would advise you to use the solution I posted above. If you still want to use the GridView then make it fill all the width/height (by using fill_parent and not wrap_content like you did for the layout_width/height) and in the onCreate method use a Handler to post a Runnable in which you retrieve the GridView‘s LayoutParams and use those to set up the adapter.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I've got a string that has curly quotes in it. I'd like to replace
We're building an app, our first using Rails 3, and we're having to build
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the

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.