0

RelativeLayout にネストされた垂直 LinearLayout にネストされた水平 LinearLayout があります。幅を埋める5つのイメージビューがあり、ウェイトを使用して均等に配置しています。実行時に 1 ~ 5 個のイメージビューをランダムに埋めます。それらは等間隔のままですが、親の左側を抱き締める代わりに、私がドキュメントで読んだのがデフォルトであり、右側を抱きしめます。私はgravity:leftとscaleType="fitStart"を試しました。このレイアウトを別の相対レイアウトにネストし、alignParentLeft を使用してみました。LinearLayout の代わりに RelativeLayout を使用すると、画像が左に配置されますが、均等に配置されないため、オプションではありません。

以下は、私のXMLファイルの関連部分です

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Game1" >

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:weightSum="7">

<LinearLayout
    android:id="@+id/animal_images_row1"
    android:layout_width="fill_parent"
    android:layout_weight="1"
    android:layout_height="0dip"
    android:layout_marginTop="5dip"
    android:layout_marginBottom="5dip"
    android:layout_marginLeft="5dip"
    android:layout_marginRight="5dip"
    >
<ImageView 
    android:layout_height="wrap_content"
    android:layout_width="0dip"
    android:layout_weight="1"
    android:id="@+id/block1"
    android:contentDescription="@string/ph"
    android:scaleType="centerInside"

    />
<ImageView 
    android:layout_height="wrap_content"
    android:layout_width="0dip"
    android:layout_weight="1"
    android:id="@+id/block2"
    android:contentDescription="@string/ph"
    android:scaleType="centerInside" />
<ImageView 
    android:layout_height="wrap_content"
    android:layout_width="0dip"
    android:layout_weight="1"
    android:id="@+id/block3"
    android:contentDescription="@string/ph" 
    android:scaleType="centerInside"/>
<ImageView 
    android:layout_height="wrap_content"
    android:layout_width="0dip"
    android:layout_weight="1"
    android:id="@+id/block4"
    android:contentDescription="@string/ph"
    android:scaleType="centerInside" />
<ImageView  
    android:layout_height="wrap_content"
    android:layout_width="0dip"
    android:layout_weight="1"
    android:id="@+id/block5"
    android:contentDescription="@string/ph"
    android:scaleType="centerInside" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>

簡潔にするために、xml ファイルの残りの部分を削除しました。助けてくれてありがとう!

編集: スクリーン ショットを追加します。 5 つの ImageView のうち 2 つが占有されています。 それらを左に揃えたいときに右に揃えます。

5 つの ImageView がすべて占有され、正しく配置されています。

4

1 に答える 1