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