0

I am working with a custom listview which has 6 fields so i used horizontal scroll view with weight in each fields for required spacing among fields.Here is the code for Activity `

<HorizontalScrollView
    android:id="@+id/horizontalScrollView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentTop="true" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:background="#898ea0"
            android:orientation="horizontal"
            android:weightSum="11" >

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="15dp"
                android:layout_weight="2"
                android:text="Name" />

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_weight="2"
                android:text="Site Name" />

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_weight="1.5"
                android:text="Plot No" />

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_weight="2.3"
                android:text="Booking Id" />

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_weight="1.6"
                android:text="Booking Date" />

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_weight="1.6"
                 android:layout_marginRight="8dp"
                android:text="Cancel Date" />
        </LinearLayout>


            <ListView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/cancel_booking_listView"
                android:background="#163330">

            </ListView>
    </LinearLayout>
</HorizontalScrollView>

`

And in the listview row item i am using all fields with same weight then also unable to get an equal spacing among the fields. Here is my custom rowlist code `

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:background="#eee"
        android:orientation="horizontal"
        android:weightSum="11" >

        <TextView
            android:id="@+id/cb_custmrnameTv"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="8dp"
            android:layout_weight="2"
            android:text="Name" />

        <TextView
            android:id="@+id/cb_siteNameTv"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_weight="2"
            android:text="Site Name" />

        <TextView
            android:id="@+id/cb_plotNoTv"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_weight="1.5"
            android:text="Plot No" />

        <TextView
            android:id="@+id/cb_bookingIdTv"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_weight="2.3"
            android:text="Booking Id" />

        <TextView
            android:id="@+id/cb_bookingDateTv"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_weight="1.6"
            android:text="Booking Date" />

        <TextView
            android:id="@+id/cb_cancelDateTv"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_weight="1.6"
            android:layout_marginRight="5dp"
            android:text="Cancel Date" />
    </LinearLayout>
</HorizontalScrollView>

` For better understanding here is screen shot of the view which i am getting.you can see here every rows have their own spacing.enter image description here

I need to implement equal spacing among all fields. Any Idea to resolve it ??

Zafar Imam
  • 319
  • 3
  • 11

2 Answers2

0

Try to use

android:layout_width="match_parent"

in TextView field. Also you may need to use table layout for proper spacing.

Peter
  • 123
  • 1
  • 6
  • android:layout_width="match_parent" it is also providing the same view there is no change. – Zafar Imam Jan 03 '16 at 09:31
  • I've tried to implement your layouts in my code and found that you need to use custom Row elements. You will append a row layout instead of a string. This can help you: http://stackoverflow.com/questions/15832335/android-custom-row-item-for-listview – Peter Jan 04 '16 at 11:20
0

I resolved this problem by using a custom header view for listview with same number of fields and weight as per custom row list and removed fields from main layout. My Cusotmer rowlist_header view is :`

<HorizontalScrollView
    android:id="@+id/horizontalScrollView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentTop="true" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:orientation="horizontal"
        android:weightSum="11" >

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="15dp"
            android:layout_weight="2"
            android:text="Name" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_weight="2"
            android:text="Site Name" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_weight="1.5"
            android:text="Plot No" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_weight="2.3"
            android:text="Booking Id" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_weight="1.6"
            android:text="Booking Date" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_weight="1.6"
            android:text="Cancel Date" />
    </LinearLayout>
</HorizontalScrollView>

`

and added this view to my listview header as

listView = (ListView) findViewById(R.id.cancel_booking_listView);

     final View headerView = getLayoutInflater().inflate(R.layout.rowlist_header,
             listView , false);
     listView .addHeaderView(headerView);
Zafar Imam
  • 319
  • 3
  • 11