0

私は Android 用のメモリー ゲームに取り組んでいますが、レイアウトに少し問題があります。

ゲームの種類 (イージー、ミディアム、ハード) ごとに 3 つの異なるレイアウトがあり、一致させる必要がある 4x4、5x5、または 6x6 の画像が画面に表示されます。

ImageAdapter を使用して画像を取得し、画面に画像を表示するために使用している GridView を埋めています。

Easy ゲームの XML ファイル (4x4 画像) は次のとおりです。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">

    <RelativeLayout 
        android:id="@+id/mainBar"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:gravity="center">
         <TextView 
           android:id="@+id/player1"
           android:layout_alignParentLeft="true"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:text="Player1 - "
           />

        <TextView 
           android:id="@+id/player1Score"
           android:layout_toRightOf="@+id/player1"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:text="00 "
           />

          <TextView 
           android:id="@+id/player2Score"
           android:layout_alignParentRight="true"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:text="00"
           />

        <TextView 
           android:id="@+id/player2"
           android:layout_toLeftOf="@+id/player2Score"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:text="Player2 - "
           />

    <Chronometer
        android:id="@+id/time"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:text="02:00" />

    </RelativeLayout>


   <GridView
       android:id="@+id/gridview"
       android:layout_width="fill_parent"
       android:layout_height="fill_parent"
       android:layout_alignParentBottom="true"
       android:layout_below="@id/mainBar"
       android:gravity="center_vertical|center_horizontal"
       android:numColumns="4">
</GridView>



</RelativeLayout>

唯一の問題は、画面サイズが小さいエミュレーターでアプリを実行すると、画像が引き伸ばされて見えることです....(IMG#1を参照)..私が本当にこのように見せたいとき..(サイズに関係なく、すべての画面で IMG#2 を参照してください。

画像#1

画像#2

異なるリソースを使用しています (ldpi、mdpi、hdpi の異なるイメージ)。

4

2 に答える 2

0

あなたが抱えている問題は、複数の画面密度をサポートしている間は、複数の物理的な画面サイズをサポートしていないということです。そのため、小さい画面では画像が大きく見え、ゆがみ始めます。

これを解決するために、電話のサイズごとに個別のレイアウトを作成できます:小、通常、大、x大。

ただし、それは非常に面倒なので、レイアウトxmlがすべての電話サイズでスケーリングされるように、線形レイアウトと重みを使用する傾向があります。

この場合、内部に4つの水平線形レイアウトを持つ1つの垂直線形レイアウトを作成する必要があります。

于 2012-06-27T02:13:58.037 に答える
0

これを使用して、正しい物理画面サイズを見つけます。

if ((getResources().getConfiguration().screenLayout & 
    Configuration.SCREENLAYOUT_SIZE_MASK) == 
        Configuration.SCREENLAYOUT_SIZE_LARGE) {
    // on a large screen device ...

}

ソース:コードを使用してデバイスの画面サイズのカテゴリ (小、通常、大、特大) を判別する方法は?

于 2012-06-27T02:40:19.173 に答える