2

ビューで使用するための簡単な9パッチPNG写真を作成しようとしていImageButtonますが、正しくスケーリングされていません。たとえば、私が使用している9patchPNG画像は次のとおりです。

ここに画像の説明を入力してください

ただし、これはスケーリング方法です。

ここに画像の説明を入力してください

これはボタンの私のXMLです:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"  >

<ImageButton
    android:id="@+id/add_challenge1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:background="@drawable/lockedbutton1"
    android:onClick="add1" />

<ImageButton
    android:id="@+id/add_challenge2"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:background="@drawable/lockedbutton1"
    android:onClick="add2" />

<ImageButton
    android:id="@+id/add_challenge3"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:background="@drawable/lockedbutton1"
    android:onClick="add3" />

<ImageButton
    android:id="@+id/add_challenge4"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:background="@drawable/lockedbutton1"
    android:onClick="add4" />

<ImageButton
    android:id="@+id/add_challenge5"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:background="@drawable/lockedbutton1"
    android:onClick="add5" />                          
</LinearLayout> 

均等に引き伸ばされてロックを中央に維持するのではなく、画像がコンテンツ(ロック)で左よりもはるかに右に拡大縮小されている理由はよくわかりません。なぜこれが起こっているのかについてのアイデアはありますか?たくさんの人が助けを提供してくれてありがとう。

4

1 に答える 1

1

9-patch からロック画像を取り出し、ロックで別の PNG を作成し、android:src代わりにそれを定義します。ボタンを使用して中央に配置しますandroid:layout_gravity=center

于 2012-11-15T03:38:03.963 に答える