我想在布局的底部放置一个按钮。我还用layout_alignParentTop放置了一个 ImageView ,我的问题是我的 ImageView 隐藏了我的按钮。 我该如何解决这个问题?
<?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>
关于java - 按钮与底部对齐,从 ImageView 中隐藏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58832805/