Android 为什么我在RelativeLayout中的ImageView的顶部和底部都有空白?
我正在使用relativelayout来覆盖图像。到目前为止,在我测试过的所有屏幕尺寸(从2.7到10.1英寸)上,我的图像顶部总是有空白。在我的IDE中,我总是看到我的relativelayout在图像的顶部和底部造成了额外的空间 为什么呢?我已经将所有高度属性设置为Android 为什么我在RelativeLayout中的ImageView的顶部和底部都有空白?,android,android-linearlayout,android-relativelayout,Android,Android Linearlayout,Android Relativelayout,我正在使用relativelayout来覆盖图像。到目前为止,在我测试过的所有屏幕尺寸(从2.7到10.1英寸)上,我的图像顶部总是有空白。在我的IDE中,我总是看到我的relativelayout在图像的顶部和底部造成了额外的空间 为什么呢?我已经将所有高度属性设置为wrap\u content,甚至添加了adjustViewBounds属性 注意:您应该知道我的图像的大小要大得多,这意味着会有一些缩放 谢谢你的提示 代码如下: <?xml version="1.0" encoding=
wrap\u content
,甚至添加了adjustViewBounds
属性
注意:您应该知道我的图像的大小要大得多,这意味着会有一些缩放
谢谢你的提示
代码如下:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="vertical"
android:focusable="true"
android:focusableInTouchMode="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/bgf"
android:textColor="#000000"
android:textSize="25sp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:paddingRight="5dp"
android:paddingLeft="5dp"
android:paddingBottom="5dp"
android:layout_gravity="center_horizontal"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:src="@drawable/cde"
android:contentDescription="@string/cde" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:layout_gravity="center_horizontal"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:src="@drawable/fgh"
android:contentDescription="@string/abc" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
当图像缩小以适应可用区域而不丢失图像的纵横比时,会发生这种情况。您将获得空白,因为图像首先占用了可用宽度,并且根据原始图像的纵横比降低了图像的高度 为了更清楚地理解,我建议您执行以下操作:
- 将相对布局的背景色设置为某种颜色
- 在imageView中设置属性scaleType=“fitXY”李>
请务必移除您为imageView提供的填充物我遇到了确切的问题。经过一段时间的努力,我通过以下方法解决了这个问题 并将以下内容添加到我的程序中
android:adjustViewBounds="true"
它工作得很好