2

I have the following XML:-

For the list view:-

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:weightSum="1">
    <ListView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/state_listView"
        android:layout_weight="0.8"
        android:layout_alignParentLeft="true"
        android:layout_marginTop="40dp"
        android:fastScrollEnabled="true"
        android:layout_toStartOf="@+id/side_index" />
    <LinearLayout
        android:id="@+id/side_index"
        android:layout_width="50dp"
        android:layout_marginTop="40dp"
        android:layout_height="match_parent"
        android:background="#c3c3c3"
        android:gravity="center_horizontal"
        android:orientation="vertical"
        android:layout_weight="0.2"
        android:layout_alignParentRight="true">
    </LinearLayout>
</RelativeLayout>

Foe each item in the list view:-

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:weightSum="1"
    android:background="@drawable/gradient">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:weightSum="1">
        <ImageView
            android:layout_width="55dp"
            android:layout_height="49dp"
            android:id="@+id/legislator_image"
            android:layout_weight="0.19"
            android:layout_alignParentLeft="true"/>
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_marginLeft="80dp">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textStyle="bold"
                android:text="Medium Text"
                android:id="@+id/firstname"
                android:layout_marginTop="3dp" />
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="Small Text"
                android:id="@+id/details"
                android:layout_marginTop="3dp" />

        </LinearLayout>

        <ImageView
            android:layout_width="10dp"
            android:layout_height="10dp"
            android:layout_marginTop="20dp"
            android:layout_marginRight="3dp"
            android:layout_alignParentRight="true"
            android:id="@+id/getDetails"/>
    </RelativeLayout>
</LinearLayout>

For the side index bar :-

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/side_list_item"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:gravity="center"
    android:textSize="13sp" />

I have not set the margin anywhere but there is a margin on the listview and near the sidebar. I want the listview and the sidebar to take up the whole screen without any margin. I have attached an image for your reference.enter image description here

ℕʘʘḆḽḘ
  • 18,566
  • 34
  • 128
  • 235
Zxxxxx
  • 397
  • 1
  • 5
  • 16
  • Is the XML you posted displayed from a Fragment? If so, I suspect that the parent Activity's XML container may have some extra padding. Try looking for any references to padding in the containing Activity's content. – crymson Nov 18 '16 at 22:28

2 Answers2

0

I am not sure, that it will fix your problem, maybe there are something more, but it is definitely wrong in your code.

1) When you use layout_weight, you should set layout_width="0dp" (respectively layout_height="0dp" if parent layout is vertical), layout_width="0dp" will cause, that this attribute will be ignored, so layout_width can work properly.

2) And second thing. When you use layout_weight, you should set layout_width in parent layout to some definite value, in your case to match_parent instead of wrap_content

There is good explanation

Community
  • 1
  • 1
0

Change you relative layout (the one containing the ListView and the LinearLayout) width param to:

android:layout_width="match_parent"

With the android:layout_width="wrap_content" the RelativeLayout only grows as much as its contents push it sideways, so the margin is not there because you defined it, its because the Layout does not get enough width to reach the borders

Sander Rito
  • 396
  • 2
  • 8