android – ListView scrollbarStyle with margin/padding-ThrowExceptions

Exception or error:

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.

How to solve:

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"/>

###

I had the same problem of scrolling the list view. putting inside a scroll view is limiting the list view to load only one row when we want to load the list dynamically,but at last got the solution :
include

android:scrollbarAlwaysDrawVerticalTrack= "true"

and

android:fadeScrollbars="false"

properties inside the ListView Tag.

###

To have an equal margins (around and between) ListView items without having the scrollbar overlaying the ListView items, you can use the following code:

<ListView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/listView"
    android:layout_gravity="center_horizontal|top"
    android:dividerHeight="10dp"
    android:divider="@android:color/transparent"
    android:padding="10dp"
    android:scrollbarStyle="outsideOverlay"/>

###

You may create new scrollbar thumb drawable what do you want about scroll drawable margin and padding.

Use these attr

android:scrollbarThumbHorizontal="@drawable/your_drawable"
android:scrollbarThumbVertical="@drawable/your_drawable"

Leave a Reply

Your email address will not be published. Required fields are marked *