0

シンプルなフラッグゲームを作りたいです。国名が与えられ、正しい国旗を推測する必要があります。私の再生画面には、TextView と TableLayout があり、2 行に 4 つの画像があります。これらの画像は同じ寸法です。

問題は次のとおりです。TextView が 2 番目の TableRow を「縮小」するため、画像が同じ大きさではなくなります。TextView を削除すると、すべて問題ありません。

Hierachy Viewer でデバッグしようとしましたが、2 番目の TableRow のプロパティ mMeasuredHeight の値が非常に高いことがわかりました (16777526)

私のプレイアクティビティxml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:padding="4dp"
    tools:context=".PlayTimeModeActivity" >

    <TextView
        android:id="@+id/tvFlagName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:text="Hello"
        android:textSize="50dp" />

    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center_horizontal" >

        <TableRow>

            <ImageView
                android:id="@+id/ivFlag1"
                android:layout_margin="4dp"
                android:contentDescription="@string/cdFlag1" />

            <ImageView
                android:id="@+id/ivFlag2"
                android:layout_margin="4dp"
                android:contentDescription="@string/cdFlag2" />
        </TableRow>

        <TableRow>

            <ImageView
                android:id="@+id/ivFlag3"
                android:layout_margin="4dp"
                android:contentDescription="@string/cdFlag3" />

            <ImageView
                android:id="@+id/ivFlag4"
                android:layout_margin="4dp"
                android:contentDescription="@string/cdFlag4" />
        </TableRow>
    </TableLayout>
</LinearLayout>

追加情報が必要ですか?

この画像のレイアウトをもっとうまくできないだろうか?

編集:画像はかなり高解像度です

4

1 に答える 1

0

これを試して:

レイアウトのルート ( LinearLayout) に次の属性android:layout_width="match_parent"を持たせ、android:layout_height="match_parent"

TableLayout持つように設定しますandroid:layout_height="wrap_content"。これにより、Hello テキストを押しつぶすのではなく、テキストが配置された後に画面上の残りのスペースを占有します。

TableRow追加ごとにandroid:layout_weight="1". これにより、各行が で均等なスペースを占めるようになりTableLayoutます。

表のそれぞれについてImageView、 を設定しandroid:layout_weight="1"ます。繰り返しますが、これにより、各フラグに均等なスペースが設定されます。

フラグはそれに応じてスケーリングする必要があります。スケーリングが正しくない場合は、ImageViewforで別の値を試してくださいandroid:scaleType

于 2012-07-05T00:44:32.327 に答える