Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/225.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java ImageView留下了大量的可用空间_Java_Android_Xml_Android Studio - Fatal编程技术网

Java ImageView留下了大量的可用空间

Java ImageView留下了大量的可用空间,java,android,xml,android-studio,Java,Android,Xml,Android Studio,我需要用图片做一张桌子。所以我决定使用TableLayout(由于权重总和的原因,我使用LinearLayout代替TableRow)。 有一个代码: <TableLayout android:layout_width="wrap_content" android:layout_height="wrap_content"> <LinearLayout android:orientation="horizontal"

我需要用图片做一张桌子。所以我决定使用TableLayout(由于权重总和的原因,我使用LinearLayout代替TableRow)。 有一个代码:

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

这不是一个完整的代码,在我的应用程序中,我动态地执行它,但它不会改变本质

因此,问题出现在下图中:


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

这是因为ImageView自动检测真实图像的宽度和高度

但是,宽度不够,因此ImageView会自动调整图像大小以适应其宽度

这就是为什么它们的高度仍然在那里,并且像你提到的那样显示为自由空间

如何解决

一定要加上

android:adjustViewBounds="true"
在ImageView中

或者只是点击这个复选框

您还可以设置

android:scaleType="centerCrop"

也许你应该考虑使用GRIDVIEW来代替这个动态Tabelayay/LoopeDay/IVIEVIEW。你想要你的图像全屏(高度)正确吗?@阿姆谢尔,我想用图像比例占据整个宽度,并且必须选择高度,以便图像在宽度上变化。但是这个自由空间让我失望:(