这是我当前的布局代码:
<?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"
这使得它总是从顶部开始,这导致隐藏你的注销按钮。
您应该进行两项更改以获得所需的内容。
从
<ListView
中删除android:layout_alignParentTop="true"
并将其添加到注销ImageButton
。将
android:layout_below="@+id/buttonLogOut"
添加到ListView
。从注销按钮中移除
android:layout_below="@+id/list_of_messages"
。
关于安卓布局 : Why is my button always UNDERNEATH the ListView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44487234/