安卓布局 : Why is my button always UNDERNEATH the ListView?

标签 android layout

这是我当前的布局代码:

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:padding="16dp"
    android:background="@drawable/background"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ImageButton
        android:layout_above="@+id/list_of_messages"
        android:background="@android:color/transparent"
        android:id="@+id/buttonLogOut"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/button_log_out"
        android:paddingLeft="60dp" />
  <ImageButton
        android:background="@android:color/transparent"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:clickable="true"
        android:src="@drawable/button_Send"
        android:id="@+id/fab"
        android:layout_alignParentBottom="true"
        android:layout_alignParentEnd="true" />
    <EditText
        android:layout_toLeftOf="@+id/fab"
        android:layout_alignParentBottom="true"
        android:layout_alignParentStart="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Your message"
        android:id="@+id/input" />
    <ListView
        android:background="@android:color/white"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:layout_alignParentStart="true"
        android:layout_above="@+id/fab"
        android:divider="@android:color/transparent"
        android:dividerHeight="16dp"
        android:id="@+id/list_of_messages"
        android:layout_marginBottom="16dp" />
</RelativeLayout>

这就是它的样子:Screenshot

注销按钮始终位于白色部分下方。 (我只是放了个白底看看,ListView覆盖了多少)。

所以 - 它总是覆盖顶部的所有内容。然而,布局底部带有发送按钮和编辑文本的“上方”部分有效。

我需要将按钮放在白色中间部分的顶部。为什么它不起作用?我通常会切换到线性布局,但在这个特定示例中我不能这样做。在 lin 布局中,我只会添加权重 10/80/10。但在这里它不起作用我做错了什么? :/

最佳答案

问题是你已经为你的 ListView 设置了 android:layout_alignParentTop="true" 这使得它总是从顶部开始,这导致隐藏你的注销按钮。

您应该进行两项更改以获得所需的内容。

  1. ListView 中删除 android:layout_alignParentTop="true" 并将其添加到注销 ImageButton

    <
  2. android:layout_below="@+id/buttonLogOut"添加到ListView

  3. 从注销按钮中移除 android:layout_below="@+id/list_of_messages"

关于安卓布局 : Why is my button always UNDERNEATH the ListView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44487234/

相关文章:

android - 无法在 5.1 上从 Android 手机提取数据库文件

html - 表格旁边的 float 图像,宽度为 100%

qt - 如何使用 Qt 使用鼠标更改网格布局单元格的大小?

android - 如何删除旧的通知 channel ?

android - DialogFragment 泄漏内存

android - LazyColumn 如何与其他可组合项一起适应屏幕?

html - 无法获得扩展整个页面的两个背景图像?

html - 创建位于屏幕下方的页脚元素

html - 这个空白是从哪里来的呢?

android - 子项目 list 对主项目的影响