Android 组织 RelativeLayout

Android organize RelativeLayout

我想这样组织我的相对布局(黑色:imageView,红色:ImageView,绿色:textView)。

但是 android 似乎将黑色 ImageView 处理为四边形而不是矩形。

这是 xml

的重要部分
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingLeft="@dimen/activity_vertical_margin"
    android:paddingRight="@dimen/activity_vertical_margin">

      <RelativeLayout
        android:id="@+id/rl"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <ImageView
            android:id="@+id/iv1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:contentDescription="@string/iv_cd_default"
            android:src="@drawable/blackImage"
            android:scaleType="centerInside"/>

        <ImageView
            android:id="@+id/iv2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:contentDescription="@string/iv_cd_default"
            android:src="@drawable/redImage"
            android:layout_alignParentTop="true"
            android:layout_alignRight="@+id/iv1"
            android:layout_alignEnd="@+id/iv1" />

        <TextView
            android:id="@+id/tv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="some text here"
            android:layout_alignBottom="@+id/iv1"
            android:layout_alignRight="@+id/iv1"
            android:layout_alignEnd="@+id/iv1"/>
    </RelativeLayout>
    ....

您可能需要 FrameLayout 而不是 RelativeLayout。

你的 ImageView 应该有 android:adjustViewBounds="true",像这样:

<ImageView
            android:id="@+id/iv1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:adjustViewBounds="true"
            android:contentDescription="@string/iv_cd_default"
            android:src="@drawable/blackImage"
            android:scaleType="centerInside"/>