0
Ich habe ein Feld für das Spiel Tic-Tac-Toe. Jede Zelle ist ein ImageButton. Wenn Sie darauf klicken, wird ein Bild eingefügt. Aber es gibt einige leere Stelle auf dem Oben und Unten:Leerer Platz in ImageButton
fragment_game.xml
<TableLayout
android:id="@+id/tableGame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="50dp"
android:background="@android:color/black">
<TableRow
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<ImageButton
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="2dp"
android:layout_weight="1"
android:background="@android:color/white" />
<ImageButton
android:id="@+id/button3"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="2dp"
android:layout_weight="1"
android:background="@android:color/white" />
<ImageButton
android:id="@+id/button2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="2dp"
android:layout_weight="1"
android:background="@android:color/white" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<ImageButton
android:id="@+id/button9"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="2dp"
android:layout_weight="1"
android:background="@android:color/white" />
<ImageButton
android:id="@+id/button5"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="2dp"
android:layout_weight="1"
android:background="@android:color/white" />
<ImageButton
android:id="@+id/button4"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="2dp"
android:layout_weight="1"
android:background="@android:color/white" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<ImageButton
android:id="@+id/button8"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="2dp"
android:layout_weight="1"
android:background="@android:color/white" />
<ImageButton
android:id="@+id/button7"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="2dp"
android:layout_weight="1"
android:background="@android:color/white" />
<ImageButton
android:id="@+id/button6"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="2dp"
android:layout_weight="1"
android:background="@android:color/white" />
</TableRow>
</TableLayout>
Und Fragment_game.java
final ImageButton btn = (ImageButton) V.findViewById(R.id.button5);
btn.setScaleType(ImageButton.ScaleType.FIT_CENTER);
btn.setAdjustViewBounds(true);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
btn.setImageResource(R.drawable.qwe);
}
});
Ich möchte das Bild auf die Größe der Zelle strecken.
Nr tun es helfen, spielt keine. – Farad
@Farad Ich möchte sagen, dass Sie YOu Layout Marge entfernen und setzen ist 0dp –