1

AndroidでTicTacToeをやっています。ImageButton をクリックすると、ボタンのサイズに関係なく、アプリを表示する画像がコンポーネントを拡大します。

○×ゲーム

属性android:scaleType="fitCenter"(almost fitXYcenterInsidefitCenterfitStart) を使用して、コンポーネント内に画像を収めようとしましたが、うまくいきませんでした。

これはXML私の ImageButton の私のコードの一部です:

 <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center" >

        <ImageButton
            android:id="@+id/btn1"
            android:layout_width="wrap_content"
            android:layout_height="100dp"
            android:layout_weight="0.246"
            android:onClick="onDonGato"
            android:text="" />

        <ImageButton
            android:id="@+id/btn2"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="0.246"
            android:onClick="onDonGato"
            android:scaleType="fitCenter"
            android:text="" />

        <ImageButton
            android:id="@+id/btn3"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="0.246"
            android:onClick="onDonGato"
            android:scaleType="fitCenter"
            android:text="" />

 </LinearLayout>

アプリを実行している Android デバイスは考慮していません (Android 仮想デバイスでゲームを実行したところ、同じ問題が発生したためです)。

私の問題を解決するための助けに感謝します。ありがとう。

4

4 に答える 4

0

私の知る限り、画像ボタンの中央に画像を配置することはできません...オプションは、テキストの上、下、およびテキストの左右の中央にあります...

イメージ ボタンの代わりに切り替えてImageView、ボタンと同じ効果を持つスタイルを作成することをお勧めします。

GridView他のオプションは、 with とImageViewinsideを介して行うことですが、それはより不必要な作業です...

于 2014-10-03T06:06:12.267 に答える
0

使用する必要がありますandroid:scaleType="fitXY"

于 2014-10-03T06:08:09.473 に答える