Я новичок в разработке android, и я пытаюсь создать connect4 с несколькими размерами сетки (5x4, 7x6, 10x7).
Моя сетка - это Tablelayout (созданный в xml-файле) с включенным ImageButton (созданным в Activty). Фон ImageButton имеет соотношение 1: 1 (102px * 102px). Какой бы размер сетки ни выбирал пользователь, я бы не хотел сохранять все одиночное соотношение ImageButton равным 1: 1, а изменял размер / масштаб таблицы TableLayout, чтобы они помещались в нем без горизонтального / вертикального растягивания ImageButton.
В xml:
<TableLayout
android:id="@+id/tableForButtons"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginTop="0dp"
android:layout_marginBottom="75dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:stretchColumns="*"
android:layout_centerHorizontal="true">
</TableLayout>
В деятельности:
for (int row = 0; row < NUM_ROWS; row++) {
TableRow tableRow = new TableRow(this);
tableRow.setLayoutParams(new TableLayout.LayoutParams(
TableLayout.LayoutParams.MATCH_PARENT,
TableLayout.LayoutParams.MATCH_PARENT,
0.05f
));
table.addView(tableRow);
for (int col = 0; col < NUM_COLS; col++) {
final int FINAL_COL = col;
final ImageButton button = new ImageButton(this);
button.setLayoutParams(new TableRow.LayoutParams(
0,
TableRow.LayoutParams.MATCH_PARENT,
0.05f
));
button.setBackgroundResource(R.mipmap.single_case);
button.setPadding(0,0,0,0);
button.setScaleType(ImageView.ScaleType.FIT_XY);
buttons[row][col] = button;
...
}
}
Вот мои настоящие взгляды:
![Streched cells problem](https://image.noelshack.com/fichiers/2019/26/7/1561911420-connect4.png)