arnoapp
arnoapp

Reputation: 2506

Android: ListView has strange margins

I'm trying to make an app with an action bar, floating button and ListView.

When I add the ListView in Android Studio it has always big margins to all sides.

Whatever I change in the layout code it doesn't help it always looks like this: enter image description here

My layout code looks like this:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="appenzeller.de.glimpse.MainActivity">

    <ListView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/mainList" />

    <LinearLayout
        android:id="@+id/ly_bar_bottom"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:gravity="right"
        android:orientation="horizontal">
        <android.support.design.widget.FloatingActionButton
            android:id="@+id/button_addc"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|end"
            android:layout_margin="28dp"
            android:src="@drawable/ic_add_white_18dp"
            android:onClick="addNewEntry"
            app:borderWidth="0dp"
            app:elevation="6dp"
            app:pressedTranslationZ="12dp" />
    </LinearLayout>

</RelativeLayout>

What am I doing wrong?

Upvotes: 1

Views: 102

Answers (2)

Divyansh Pagaria
Divyansh Pagaria

Reputation: 21

Your relative layout is using padding which means you are leaving some space from sides.

Removing the following lines will remove padding

android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"

if you want to remove padding from top and bottom as well you can remove following tag as well

android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingTop="@dimen/activity_vertical_margin"

Upvotes: 1

G. Kalender
G. Kalender

Reputation: 491

Try to remove

android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"

from your RelativeLayout. You said "all sides", I can only see left/right. But if it's all sides you also have to remove "paddingTop" and "paddingBottom".

Upvotes: 5

Related Questions