GridView: How can I get rid of extra space from my GirdView object?

Posted by Lajos Arpad on Stack Overflow See other posts from Stack Overflow or by Lajos Arpad
Published on 2010-06-02T00:53:55Z Indexed on 2010/06/02 3:33 UTC
Read the original article Hit count: 365

Filed under:
|

Hello,

I'm writing an application for Android phones for Human vs. Human chess play over the internet. I was looking at some tutorials, to learn how to develop Android applications and found a very nice example of making galleries (it was a GridView usage example for making a gallery about dogs) and the idea came to draw the chess table using a GridView, because the example project also handled the point & click event and I intended to use the same event in the same way, but for a different purpose. The game works well (currently it's a hotseat version), however, I'm really frustrated by the fact that whenever I rotate the screen of the phone, my GridView gets hysterical and puts some empty space in my chess table between the columns. I realized that the cause of this is that the GridView's width is the same as its parent's and the GridView tries to fill its parent in with, but there should (and probably is) be a simple solution to get rid of this problem. However, after a full day of researching, I haven't found any clue to help me to make a perfect drawing about my chess table without a negative side effect in functionality. The chess table looks fine if the phone is in Portrait mode, but in Landscape mode it's far from nice. This is how I can decide whether we are in Portrait or Landscape mode:

((((MainActivity)mContext).getWindow().getWindowManager().getDefaultDisplay().getWidth()) < ((MainActivity)mContext).getWindow().getWindowManager().getDefaultDisplay().getHeight())

In the main.xml file the GridView is defined in the following way:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              >
    <GridView xmlns:android="http://schemas.android.com/apk/res/android"
              android:id="@+id/gridview"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:numColumns="8"
              android:verticalSpacing="0dp"
              android:horizontalSpacing="0dp"
              android:stretchMode="columnWidth"
              android:gravity="center"
              >
    </GridView>
...
</LinearLayout>

I appreciate any help with the problem and thank you for reading this.

© Stack Overflow or respective owner

Related posts about java

Related posts about android