Android 安卓的相对论问题

Android 安卓的相对论问题,android,android-layout,Android,Android Layout,我是Java和Android新手,我面临着这个问题: 我想在矩形的左上角添加一张照片。然而,我的照片的ImageView总是有更多的空间,因此,它在顶部创建了一个我不想拥有的空白空间。以下是一个屏幕截图: 我的布局代码是: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:la

我是Java和Android新手,我面临着这个问题:

我想在矩形的左上角添加一张照片。然而,我的照片的
ImageView
总是有更多的空间,因此,它在顶部创建了一个我不想拥有的空白空间。以下是一个屏幕截图:

我的布局代码是:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    android:padding="25dp">

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:src="@drawable/profile_frame" />

<ImageView
    android:id="@+id/imageView2"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/imageView1"
    android:layout_centerVertical="true"
    android:src="@drawable/foto_facebook_juan_mejorada" />

</RelativeLayout>

试试这个:

android:scaleType="fitStart"
android:adjustViewBounds="true"
可能是因为 图像的大小。如果图像不适合给定的空间,它将添加空白。

//请尝试这种方法
// try this way
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="30dp">
    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/profile_frame" />

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
        android:scaleType="fitXY"
        android:src="@drawable/foto_facebook_juan_mejorada" />
    </FrameLayout>

</LinearLayout>

这是因为您的图像尺寸小于该尺寸。你已经给出了包装内容。将width设置为match_parent并将
android:scaleType=“fitXY”
设置为true。这是正确的答案!你给我的,对吗?将adjustViewBounds设置为true。