我想组织我的相对布局(黑色:imageView,红色:ImageView,绿色:textView)。
但是android似乎处理黑色ImageView就像一个quadrat而不是一个矩形。
这是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>
....
答案 0 :(得分:1)
你的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"/>
答案 1 :(得分:0)
你可能想要FrameLayout而不是RelativeLayout。