如何缩放动态Tablelayout以保持单个单元格imageButton比例为1:1 android

时间:2019-06-30 16:21:15

标签: android android-layout imagebutton

我是android developmentpement的初学者,我正在尝试制作具有多个网格大小(5x4、7x6、10x7)的connect4。 我的网格是一个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

2 个答案:

答案 0 :(得分:0)

您可以尝试以下操作:

=ArrayFormula(lower(TRANSPOSE(split(join(" ",left(A1:A3,len(A1:A3)-1))," "))))

答案 1 :(得分:0)

您只需要设置ORDER BY的动态高度和宽度。

ImageButton

让我知道您是否有任何问题。