java - ImageView 留有大量可用空间

标签 java android xml android-studio

我需要用图片制作一张 table 。所以我决定用 TableLayout 来做(而不是 TableRow,我使用 LinearLayout 因为 weightSum)。 有一个代码:

<TableLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

        <LinearLayout
            android:orientation="horizontal"
            android:weightSum="3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">

            <ImageView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:src="@drawable/card_shirt"
                android:id="@+id/imageView"
                />

            <ImageView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:src="@drawable/card_shirt"
                android:id="@+id/imageView2"/>

            <ImageView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:src="@drawable/card_shirt"
                android:id="@+id/imageView3"/>
        </LinearLayout>

        <LinearLayout
            android:orientation="horizontal"
            android:weightSum="3"
            android:layout_width="wrap_content"
            android:layout_height="match_parent">

            <ImageView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:src="@drawable/card_shirt"
                android:id="@+id/imageView4"/>

            <ImageView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:src="@drawable/card_shirt"
                android:id="@+id/imageView5"/>

            <ImageView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:src="@drawable/card_shirt"
                android:id="@+id/imageView6"/>
        </LinearLayout>
</TableLayout>

这不是完整的代码,在我的应用程序中我是动态执行的,但它并没有改变本质。

所以问题出在下面的图片上:

enter image description here

每张图片上方和下方的空闲空间是多少?我怎样才能摆脱它?

最佳答案

这是因为ImageView会自动检测真实图片的宽高

但是,宽度不够,所以 ImageView 会自动调整图像的大小以适应它的宽度

这就是为什么他们的高度仍然存在,并像您提到的那样显示为可用空间

如何解决

确保添加

android:adjustViewBounds="true"

在 ImageView 中

或者只是点击这个复选框

enter image description here

关于java - ImageView 留有大量可用空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31432067/

相关文章:

java - 删除填充日期的 vector 中的周末

java - 我的 Android 应用程序崩溃了,即使我捕获了它所说的导致崩溃的异常

android - EditText最大字符限制超过回调

android - 有没有办法避免在带有自定义 View (Android)的 xml 中使用完整的包名称?

java - JIBX 绑定(bind)和 Google 通讯录(使用Flexible=true)

java - Java 中的 CRL 验证

java - 尝试写入文件时发生 Android ENOENT 错误

java - 在 IDEA 中覆盖 Android 的默认构建脚本?

json - TTL 文件格式 - 我不知道这是什么

xml - XSLT - 选择另一个节点之后的节点