【问题标题】:How work TableLayout with imageButton?TableLayout 如何与 imageButton 一起工作?
【发布时间】:2017-10-12 21:31:03
【问题描述】:

我有桌子:

<TableRow
        android:layout_weight="1">
        <ImageButton
            android:background="#111111"
            android:layout_height="match_parent"
            android:src="@drawable/w"
            android:scaleType="fitXY"
            />
        <ImageButton
            android:background="#111111"
            android:layout_height="match_parent"
            android:scaleType="fitXY"
            />
        <ImageButton
            android:background="#111111"
            android:layout_height="match_parent"
            android:scaleType="fitXY"
            />
    </TableRow>
    <TableRow
        android:layout_weight="1">
        <ImageButton
            android:background="#111111"
            android:layout_height="fill_parent"
            />
        <ImageButton
            android:background="#111111"
            android:layout_height="fill_parent"
            />
        <ImageButton
            android:background="#111111"
            android:layout_height="fill_parent"
            />
    </TableRow>
    <TableRow
        android:layout_weight="1">
        <ImageButton
            android:background="#111111"
            android:layout_height="fill_parent"
            />
        <ImageButton
            android:background="#111111"
            android:layout_height="fill_parent"
            />
        <ImageButton
            android:background="#111111"
            android:layout_height="fill_parent"
            />
    </TableRow>
</TableLayout>

最初,一切看起来都不错,但是当我插入图片时,它会立即变形,以适应图像,如屏幕截图所示。告诉我如何解决这个问题? good tablebad table

【问题讨论】:

  • 这是因为图像的大小不同,您必须使用位图或任何库调整图像大小。我希望这会奏效。

标签: android xml imagebutton tablelayout tablerow


【解决方案1】:

在 ImageButtons 上,将 AdjustViewBounds 设置为 true。然后将 scaletype 设置为 FitXY。我使用权重和视图来调整大小和位置。对于 TableRow 中的 ImageButton,layout_width 必须设置为 0 才能使权重起作用。它可以很好地扩展。这应该在 xml 中的 ImageButton 下:

android:layout_height="match_parent"
android:layout_weight="0dp"
android:scaleType="fitXY"
android:layout_weight="1"
android:adjustViewBounds="true"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-02-02
    • 2017-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-09
    相关资源
    最近更新 更多