我需要用图片制作一张 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>
这不是完整的代码,在我的应用程序中我是动态执行的,但它并没有改变本质。
所以问题出在下面的图片上:
每张图片上方和下方的空闲空间是多少?我怎样才能摆脱它?
最佳答案
这是因为ImageView会自动检测真实图片的宽高
但是,宽度不够,所以 ImageView 会自动调整图像的大小以适应它的宽度
这就是为什么他们的高度仍然存在,并像您提到的那样显示为可用空间
如何解决
确保添加
android:adjustViewBounds="true"
在 ImageView 中
或者只是点击这个复选框
关于java - ImageView 留有大量可用空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31432067/