ListView scrollbarStyle with margin/padding
Asked Answered
C

4

22

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.

Crawford answered 9/2, 2012 at 10:53 Comment(2)
You can also use: android:scrollbarStyle="outsideOverlay". outsideInset puts your scrollbar outside of defined padding. "outsideOverlay" puts it inside the padding, ie looks more like google play app. This also works on gridview btw.Furness
you can add an answer to your own question and mark it as correctColeencolella
E
11

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"/>
Eyewitness answered 10/9, 2013 at 6:55 Comment(0)
B
1

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"
Brozak answered 2/10, 2013 at 9:13 Comment(0)
G
0

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.

Grader answered 18/9, 2013 at 9:13 Comment(0)
H
0

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"/>
Humor answered 14/1, 2015 at 2:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.