0

背景のButtonドローアブルandroid:layout_width="wrap_content"android:layout_height="wrap_content". ボタンにテキストはありません。ただし、その表示サイズは、幅と高さを.drawableの幅と高さに設定しない限り、drawableのサイズが少し変更されてぼやけて見えますpx。どうすればwrap_content仕事をすることができますか?または、ドローアブルのサイズが変更されたときに追加の編集を行う必要がないように、ボタンのサイズをハードコーディングする必要のない他の方法はありますか?

ここに私のXMLがあります:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" xmlns:tools="http://schemas.android.com/tools">

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

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:paddingBottom="3dp"
            android:paddingTop="3dp" >

            <Button
                android:id="@+id/btn"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/btn" />

        </RelativeLayout>
    </LinearLayout>

</ScrollView>
4

1 に答える 1

1

通常のボタンの代わりに ImageButton を使用します。プロパティへのアクセスを提供しandroid:src、背景としてではなく、そこに画像を設定します。「ソース」プロパティがプロパティを介して画像のサイズ変更を制御するため、背景画像は常に全体に合わせて表示されandroid:scaleTypeます。参照: http://developer.android.com/reference/android/widget/ImageButton.htmlおよびhttp://developer.android.com/reference/android/widget/ImageView.html#attr_android:scaleType

ImageButton については、 も確認する必要があることに注意してandroid:background="@null"ください。そうしないと、ソース イメージの背後にデフォルトのボタン イメージが表示されます。

編集:

これが XML の更新版です。画像の 1 つを使用しましたが、最初のボタンの上に新しいボタンを追加しました。特定の画像は長く、それほど高くはありません。通常のボタンでは、ウィジェットを埋めるために伸びて、パースペクティブが失われます。上部の新しい ImageButton では、その視点が維持されます。

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" xmlns:tools="http://schemas.android.com/tools">

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

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:paddingBottom="3dp"
            android:paddingTop="3dp" >

            <ImageButton
                android:id="@+id/new_btn"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@null"
                android:scaleType="fitCenter"
                android:src="@drawable/postwall" />

            <Button
                android:id="@+id/btn"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/new_btn"
                android:background="@drawable/postwall" />

        </RelativeLayout>
    </LinearLayout>

</ScrollView>
于 2013-03-15T15:37:34.700 に答える