我想在版式底部放置一个按钮。我也用layout_alignParentTop放置了一个图像视图,我的问题是我的图像视图隐藏了我的按钮。我该如何解决?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button android:id="@+id/btnGetMoreResults"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:text="Get more"
android:layout_alignParentBottom="true" />
<ImageView
android:layout_alignParentTop="true"
android:src="@android:drawable/ic_menu_gallery"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/btnGetMoreResults"
android:id="@+id/imageView1" />
</RelativeLayout>
看下面的图片
我应该使用CoordinatorLayout代替RelativeLayout吗?
在您的ImageView中,不要使用
android:layout_alignParentBottom="true"
您必须使用
android:layout_above="@+id/your_button"
这是最终代码,请不要忘记根据需要对其进行修改
<RelativeLayout
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_alignParentTop="true"
android:layout_above="@id/button"
android:layout_width="match_parent"
android:layout_height="0dp"/>
<Button
android:id="@+id/button"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
在imageview中使用它
android:margin_bottom="50dp";