TableLayout如何与imageButton一起使用? [英] How work TableLayout with imageButton?
问题描述
我有桌子:
<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
推荐答案
在ImageButtons上,将AdjustViewBounds设置为true.然后将比例类型设置为FitXY.我使用权重和视图来调整大小和位置.对于TableRow中的ImageButton,必须将layout_width设置为0才能使权重起作用.它的伸缩性非常好.这应该在xml中的ImageButton下:
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"
这篇关于TableLayout如何与imageButton一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!