图像覆盖了 TextView 和按钮(我什至根本看不到它们,所以我猜它们在图像后面)。附有图片。我希望 TextView 和按钮出现在 ImageView 下方。下面是我的 xml 文件。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageView
android:id="@+id/imageView9"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scaleType="fitStart"
android:src="@drawable/bw" />
<EditText
android:id="@+id/name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/imageView1"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/button" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/button2" />
</LinearLayout>
最佳答案
您可以将主布局更改为RelativeLayout
,将ImageView
设置在顶部
并将 View 包裹在ImageView
下方,在单独的布局内。
通过为 ImageView
设置 android:layout_above="@+id/linear"
,您将确保 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:orientation="vertical">
<ImageView
android:id="@+id/imageView9"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/linear"
android:layout_alignParentTop="true"
android:scaleType="fitStart"
android:src="@drawable/bw" />
<LinearLayout
android:id="@+id/linear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical"
android:gravity="center_horizontal">
<EditText
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button" />
</LinearLayout>
</RelativeLayout>
关于java - Android中ImageView覆盖其他内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53951882/