How work TableLayout with imageButton?

筅森魡賤 提交于 2020-01-05 09:09:11

问题


I have Table:

<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>

Initially, everything looks good, but when I insert a picture, it immediately deforms, adjusting to the image, as in the screenshot. Tell me how to solve this problem? good table and bad table


回答1:


On the ImageButtons, set AdjustViewBounds to true. and then set the scaletype to FitXY. I use weights and views to adjust the size and position. For an ImageButton in a TableRow, the layout_width will have to be set to 0 for the weights to work. It scales very well. This should be under an ImageButton in an xml:

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


来源:https://stackoverflow.com/questions/43956756/how-work-tablelayout-with-imagebutton

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!