Android Layout: Why does my button always NOT RAISE the ListView?
this is my current LayOut code:
<?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>
And this is what it looks like: Screenshot
The LogOut button is always under the white part. (I just put a white background to see how much the ListView is covered).
So - it always covers EVERYTHING at the top. However, the "above" part with the submit button and edittext at the bottom of the layout works.
I would need to hover the button on top of the white middle section. Why isn't it working? I usually switch to linear layout, but in this particular example, I cannot do that. In lin layout, I would just add 10/80/10 scales. But it doesn't work here. What am I doing wrong?:/
source to share
The problem is that you have set android:layout_alignParentTop="true"
for your ListView
, which makes it always beginner at the top, which causes the logout button to be hidden.
You have to make two changes to get what you want.
-
Remove
android:layout_alignParentTop="true"
fromListView
and add it to logoutImageButton
. -
Add
android:layout_below="@+id/buttonLogOut"
to youListView
. -
Remove
android:layout_below="@+id/list_of_messages"
from the logout button.
source to share