1

横の画像ボタンに配置したい画像が5つありますLinearLayout。画像はディスク上にさまざまなサイズで保存されますが、レイアウトに配置するときは、同じ高さで、0.5、1、1、1、0.5の異なる重み(レイアウトの重みの合計を意味する)にする必要がありますは4)です。このコードを使用しようとしましたが、機能しませんでした。

 <LinearLayout
    android:id="@+id/linearLayout2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:weightSum="4" >

    <ImageButton
        android:id="@+id/scrollLeft"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/left"
        android:layout_weight="0.5" />

    <ImageButton
        android:id="@+id/dog"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/dog"
        android:layout_weight="1" />

    <ImageButton
        android:id="@+id/fish"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/fish"
        android:layout_weight="1" />

    <ImageButton
        android:id="@+id/cat"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/cat"
        android:layout_weight="1" />

    <ImageButton
        android:id="@+id/scrollRight"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/right"
        android:layout_weight="0.5" />

</LinearLayout>

これを機能させるために変更できるパラメータはlayout_widthありlayout_heightますか、それともボタンごとにJavaコードからスケーリングされたビットマップを作成する必要がありますか?ありがとう!

4

1 に答える 1

0

同じ高さを定義してから、比率を維持するためにスケーリングしてみてください

<ImageView
    .... 
    android:layout_height="match_parent"
    android:scaleType="centerInside"
    .... />

match_parent高さにaを使用して編集ImageButtonsすると、が同じ高さになり、を使用して縮尺比が維持されます。scaleType

于 2012-08-20T20:08:41.520 に答える