android - 我无法将两张图片放在布局的中心

标签 android android-linearlayout android-imageview

我尝试将两张图片放在布局的中心, 但我在布局的顶部和底部有额外的空间。 图像是 png 文件。

enter image description here

我的 XML 的重要部分如下:

                    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                              android:layout_width="wrap_content"
                              android:layout_height="wrap_content"
                              android:background="@color/backDark2"
                              android:orientation="horizontal"
                        >

                <ImageView
                        android:id="@+id/imageDriverProfileFace"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_weight="1"
                        android:src="@drawable/driver"
                        />
                <ImageView
                        android:id="@+id/imageDriverProfileCar"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_weight="1"
                        android:src="@drawable/car"
                        />
                </LinearLayout>

请问如何删除提到的额外空间? 谢谢!

最佳答案

android:adjustViewBounds="true" 参数设置为您的 ImageView

关于android - 我无法将两张图片放在布局的中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29877924/

相关文章:

android - Pixel 2 设备中的临时文件夹

android - 在 ImageView 中检测触摸

android - 放大图像以填充 Android 中的整个 ImageView

android - 被其父级裁剪的 Android View 的全尺寸

android - 也可以使用按钮滑动和更改图像

android - 为什么有 insertOrThrow 而没有 updateOrThrow 或 deleteOrThrow?

java - WorkManager 不按需初始化

android - 无法在 Netbeans 中打开现有项目

java - 将相对布局转换为线性布局

Android比较出wrap_content和match_parent