1

I'm trying to write a card game for Android and I'm running into layout difficulties. I'm coding the main game screen which consists of five cards arranged vertically across the left and right and five cards arranged horizontally across the top and bottom. The problem I'm having is I need the cards to all shrink horizontally and vertically if there isn't room for all the other cards to be shown.

Below is a picture of the problem (I'm omitting the cards along the left and bottom for clarity). As you can see only four cards are shown along the right side - the bottom card is partially obscured. The View has simply run out of space, so it drops the rest of the card that doesn't fit.

Here's a link to the screenshot, since I can't post images: image

What I'd like in this situation is for Android to reduce the height of all the top cards and right cards until the bottom card is fully visible. It doesn't seem complicated, but I can't get it to work. I created the image below by using RelativeLayout and placing all top cards next to each other and all right cards below each other (with the top card on the right below the top cards). I tried adding all the cards to their own View but that didn't work either.

Any suggestions? Thanks!


OK, I got it closer (see the image link at the bottom) but now I have the opposite problem - I need to increase it. I believe it's because I shrunk the images I'm using for the suits. As you can see they are all shrunk to a small size. I would like to be able to get the LinearLayout for each button set to expand horizontally/vertically to use up all free space, without drawing the last buttons off the visible part of the LinearLayout. Ideally I would be able to drop in any size image for the suit and have that resized appropriately as well, but I'm afraid I'm asking for some circular logic or something in the layout engine.

Here is my XML file. The HandView class is what holds the five cards in each set. The 5 cards have a 5 pixel margin between them.

<?xml version="1.0" encoding="utf-8"?>
<TableLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:shrinkColumns="*"
    android:background="#FF00FF00">

    <TableRow
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:background="#FF0000FF">
        <com.herscher.euchre.ui.HandView
          android:background="#FFFF0000"
            android:layout_column="1"
            android:orientation="horizontal"
            android:id="@+id/northHandView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal" />
    </TableRow>

    <TableRow
        android:layout_height="wrap_content"
        android:layout_width="wrap_content">
        <com.herscher.euchre.ui.HandView
            android:layout_column="0"
            android:orientation="vertical"
            android:id="@+id/westHandView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <com.herscher.euchre.ui.PlayArea
            android:layout_column="1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:id="@+id/playArea" />

        <com.herscher.euchre.ui.HandView
            android:layout_column="2"
            android:orientation="vertical"
            android:id="@+id/eastHandView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </TableRow>

    <TableRow
        android:layout_height="wrap_content"
        android:layout_width="wrap_content">
        <com.herscher.euchre.ui.HandView
            android:layout_column="1"
            android:orientation="horizontal"
            android:id="@+id/southHandView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </TableRow>

</TableLayout>

New image is here

Does anyone have any suggestions?

4

1 回答 1

0

您可能想查看 usingLinearLayout的权重功能,这将强制子视图调整到可用空间的大小。在您的情况下,您可能希望它们都具有相同的重量。

于 2011-01-06T04:10:55.713 回答