MartinS
MartinS

Reputation: 6234

ListView scrollbarStyle with margin/padding

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.

Upvotes: 22

Views: 8968

Answers (4)

nurisezgin
nurisezgin

Reputation: 1570

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"

Upvotes: 1

Ashraf Alshahawy
Ashraf Alshahawy

Reputation: 1189

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

Upvotes: 0

user1788155
user1788155

Reputation: 1

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.

Upvotes: 0

Dinithe Pieris
Dinithe Pieris

Reputation: 1992

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

Upvotes: 11

Related Questions