ListView scrollbarStyle with margin/padding

MartinS picture MartinS · Feb 9, 2012 · Viewed 8.3k times · Source

Hopefully a simple one. v4.0.3

I have a ListView and want to leave a margin of 10dip right and left. The content is easy of course, but I want the divider line to have a 10dip margin right and left too.

If I add android:PaddingRight or android:layout_marginRight to the ListView or the LinearLayout which contains the ListView then this works of course, but the List scrollbar which appears down the right hand side as you scroll the list also moves in by the padding/margin distance.

I want the scrollbar indicator to remain. I've tried all the android:scrollbarStylesettings.

Answer

Dinithe Pieris picture Dinithe Pieris · Sep 10, 2013

Can do easily

<ListView
    android:id="@+id/lvDonorDetails"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:divider="@drawable/list_divider"
    android:dividerHeight="1dp"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:scrollbarStyle="outsideInset"/>

Or

<ListView
    android:id="@+id/lvDonorDetails"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:dividerHeight="1dp"
    android:padding="10dp"
    android:scrollbarStyle="outsideInset"/>