Android 如何使用imageButton处理TableLayout?
我有一张桌子:Android 如何使用imageButton处理TableLayout?,android,xml,imagebutton,tablelayout,tablerow,Android,Xml,Imagebutton,Tablelayout,Tablerow,我有一张桌子: <TableRow android:layout_weight="1"> <ImageButton android:background="#111111" android:layout_height="match_parent" android:src="@drawable/w" android:scaleType="fitXY"
<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>
起初,一切看起来都很好,但当我插入图片时,它会立即变形,并根据图像进行调整,如屏幕截图所示。告诉我如何解决这个问题?
和
在图像按钮上,将AdjustViewBounds设置为true。然后将scaletype设置为FitXY。我使用权重和视图来调整大小和位置。对于TableRow中的ImageButton,布局宽度必须设置为0,权重才能工作。它的伸缩性很好。这应该位于xml中的ImageButton下:
android:layout_height="match_parent"
android:layout_weight="0dp"
android:scaleType="fitXY"
android:layout_weight="1"
android:adjustViewBounds="true"
在ImageButtons上,将AdjustViewBounds设置为true。然后将scaletype设置为FitXY。我使用权重和视图来调整大小和位置。对于TableRow中的ImageButton,布局宽度必须设置为0,权重才能工作。它的伸缩性很好。这应该位于xml中的ImageButton下:
android:layout_height="match_parent"
android:layout_weight="0dp"
android:scaleType="fitXY"
android:layout_weight="1"
android:adjustViewBounds="true"
由于图像的大小不同,因此必须使用位图或任何库来调整图像的大小。我希望这能起作用。因为图像的大小不同,所以必须使用位图或任何库来调整图像的大小。我希望这会奏效。