1

次のことを達成するために、いくつかの XML で遊んでいます。

最初の行はバナーです (正常に動作します)。それで; 各行に 3 つのボタンがあります。ボタンがすべての水平方向のスペースを占有するようにします (つまり、画面の幅を 3 で割ります)。また、ボタンの画像は、縦横比を変更せずに、その幅にサイズ変更する必要があります。これはどのように行うことができますか?

次; ImageButtons の行を追加する場合、3 つのボタンの幅の分布を維持するために、スクロールビューで LinearLayouts をどのように「シェル化」する必要がありますか?

thnx

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_centerHorizontal="true"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/blogbanner"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:scaleType="fitXY"
        android:src="@drawable/test_banner_ad" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1" >

        <ImageButton
            android:id="@+id/imageButton1"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:scaleType="fitXY"
            android:src="@drawable/trololo" />

        <ImageButton
            android:id="@+id/imageButton2"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:scaleType="matrix"
            android:src="@drawable/scout" />

        <ImageButton
            android:id="@+id/imageButton3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:scaleType="fitEnd"
            android:src="@drawable/painting" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1" >

        <ImageButton
            android:id="@+id/imageButton4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/whoop" />

        <ImageButton
            android:id="@+id/imageButton5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/drown" />

        <ImageButton
            android:id="@+id/imageButton6"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/love" />
    </LinearLayout>



    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1" >

        <ImageButton
            android:id="@+id/imageButton7"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/shredder" />

        <ImageButton
            android:id="@+id/imageButton8"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/frog" />

        <ImageButton
            android:id="@+id/imageButton9"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/yeah03" />
    </LinearLayout>
</LinearLayout>

4

1 に答える 1

1

各行の 3 つのボタンを別の水平レイアウトに配置し、「weight」属性を使用して幅を定義します。

画像の寸法は「fill_parent」で、scaleXY を使用する必要があります

于 2012-06-04T20:46:35.363 に答える