Android XML 表格行

标签 android android-layout

图片:www.gunzhaxplz.com/xmlAndroid.png my problem http://gunzhaxplz.com/xmlAndroid.png

前言:我正在制作一个应用程序,需要在一个表格行上放置 6 张图像。

问题:我似乎无法调整图像的大小,右边的最后一张图像超出了屏幕

这是 XML:

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/TableLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >

<TableRow
    android:id="@+id/tableRow1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >




    <ImageButton
        android:id="@+id/imageButton1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/golem_square" />





    <ImageButton
        android:id="@+id/imageButton2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/lizard_square" />




    <ImageButton
        android:id="@+id/imageButton3"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:src="@drawable/baron_square" />



    <ImageButton
        android:id="@+id/imageButton4"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/dragon_square" />

</TableRow>

<TableRow
    android:id="@+id/tableRow2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <ImageButton
        android:id="@+id/ImageButton03"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/golem_square" />

    <ImageButton
        android:id="@+id/ImageButton01"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/lizard_square" />

    <ImageButton
        android:id="@+id/ImageButton02"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:src="@drawable/baron_square" />

    <ImageButton
        android:id="@+id/ImageButton04"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/dragon_square" />
</TableRow>

最佳答案

尝试在每个 ImageButton 中设置以下参数

android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:maxWidth="32dpi"
android:maxHeight="32dpi"

关于Android XML 表格行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13215909/

相关文章:

android - 如何在 Android 中为 Button 提供固定的宽度和高度

android - styles.xml 中的自定义属性

android - 九补丁图像是否可收缩?

Android 在不使用 XML 的情况下指定像素单位(如 sp、px、dp)

android - Kotlin-Android First App Unresolved Reference TextView Button etc

android - 此消息无法回收,因为它仍在使用中

android - 如何在不发疯的情况下使用 ARM DS-5 在 eclipse 中调试 Android native 库?

Android:我需要延迟通知

Android View 比较两个 View 是否相等

android - 使用android相对布局时缺少边框线