0

重複の可能性:
Android の画像ボタンの縦横比を維持するにはどうすればよいですか?

レイアウトの下部近くに画像ボタンが並んでいるので、正方形のサイコロが 5 個あります。レイアウトの幅全体を占めるようにしたいのですが、幅全体を占めながら、その縦横比を適切に維持することができないようです。現在、私のコードは次のようになっています。

 <LinearLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="60dp"
        android:layout_margin="1dp"
        android:layout_gravity="bottom" 
        > 
        <ImageButton
             android:id="@+id/die1" 
             android:layout_width="fill_parent"
             android:layout_height="wrap_content" 
             android:layout_gravity="center"
             android:adjustViewBounds="true"
             android:layout_weight="1"
             android:layout_margin="2dp"
             android:scaleType="centerInside"
             />  
        <ImageButton
             android:id="@+id/die2" 
             android:layout_width="fill_parent"
             android:layout_height="wrap_content" 
             android:layout_gravity="center"
             android:adjustViewBounds="true"
             android:layout_weight="1"
             android:layout_margin="2dp"
             android:scaleType="centerInside"
             /> .....

次のようになります。 60dp

私が含まれていない場合

android:layout_height="60dp"

次に、サイコロが歪んで次のようになります。歪んだ

ただし、「60dp」の部分を残すと、タブレットデバイスまたは高解像度のものに表示しようとすると、次のようになるという問題が発生します。

ここに画像の説明を入力

どこが間違っているのですか?

4

3 に答える 3

0

ImageButtons の幅を に設定し、左余白に収まる画像と右端の画像にfill_parentscaletype を使用します。少なくともサンプル画像に関する限り、トリックを行う必要があります。画像の比例幅が画面幅を超えると、間隔の問題が発生する可能性がありますが、問題はありません。fitStartfitEnd

于 2011-11-04T13:46:54.363 に答える
0

試す

 android:layout_height="wrap_content"

&

<LinearLayout>属性は次のようandroid:layout_height="60dp"に置き換えられますandroid:layout_height="wrap_content"

于 2011-11-01T05:26:23.087 に答える