java - 按钮与底部对齐,从 ImageView 中隐藏

标签 java android xml xamarin

我想在布局的底部放置一个按钮。我还用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> 

看下面的图片

img

我应该使用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/

相关文章:

android - 致命异常 : main java. lang.IllegalStateException:ArrayAdapter 要求资源 ID 为 TextView

php - Android 移动应用程序与 Web 主机数据库的连接

xml - 如何将特定属性转换为复杂 XML 中的元素

android - 缩进的 TabLayout

java - BlueJ Java 谜题中移动方法的条件语句

java - JButton 正在图像后面绘制

Android Binder 内部

xml - 在根节点之前选择comment()

java - 我正在用Java编写代码,但是在编译时出现了: “.java uses or overrides a deprecated API.” comes up错误

java - 流已被操作或关闭,尝试创建赛车手时获得异常