Reputation: 231
Hi I have an annoying problem I want to place a button as part of an action bar at the bottom of my listview but there is some padding just above below the last item of the listview I can't get rid of. Here is my code any help would be greatly appreciated.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawingCacheQuality="high">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:drawingCacheQuality="high"
android:paddingBottom="0dp"
android:layout_margin="0dp"
>
<ListView
android:id="@+id/messagingListView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="@null"
android:layout_margin="0dp"
android:layout_alignParentTop="true"
android:dividerHeight="10dp"
android:paddingTop="10dp"
android:paddingRight="10dp"
android:paddingBottom="0dp"
android:paddingLeft="10dp"
/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="0dp"
android:background="#FFFFFF"
android:layout_alignParentBottom="true">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="new_game"
android:textColor="#FFFFFF"
/>
</LinearLayout>
Upvotes: 1
Views: 2441
Reputation: 2817
A simpler layout would look like this :
LinearLayout
to contain the ListView
and the action barLinearLayout
used for the action bar has its height to wrap_content
so it only gets the height required by its childrenListView
has its height
to 0dp
and its weight
to 1
in order to let it take all the available space left by the action bar<?xml version="1.0"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:drawingCacheQuality="high"> <ListView android:id="@+id/messagingListView" android:layout_width="fill_parent" android:layout_height="0dp" android:layout_weight="1" android:divider="@null" android:layout_margin="0dp" android:dividerHeight="10dp" android:paddingTop="10dp" android:paddingRight="10dp" android:paddingBottom="0dp" android:paddingLeft="10dp" /> <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:padding="0dp" android:background="#FFFFFF"> <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="new_game" android:textColor="#FFFFFF" /> </LinearLayout> </LinearLayout>
If space remains, you should definitly show us the layout used for list items
Note :
In Android Studio, try to single click on the LinearLayout
to let it be highlighted in the Preview
, then on the ListView
to see if there is a gap (Use the zoom).
If you see a gap with the layout just above, it's an Android Studio Preview
bug on your computer, it works on every devices.
Upvotes: 2