1

Possible Duplicate:
programmatically Scroll to a specific position in Android ListView

I have a listview with a scrollbar. I want to shift the scrollbar down a few pixels.

android:scrollY="20dp"

I tried setting this in my listView but nothing changes.

Any ideas on how to achieve the offset?

Community
  • 1
  • 1
serenskye
  • 3,467
  • 5
  • 35
  • 51
  • Nope, I don't want to programatically scroll, I want to move the entire bar down – serenskye Nov 01 '12 at 14:56
  • 1
    @AleksG: I am not sure the two questions are related. I think the OP wants to move the position of scrollbar in the `ListView` down a few pixels and not the scroll to an item in the `ListView`. But I could be wrong. – Siddharth Lele Nov 01 '12 at 14:56
  • Yeah @SiddharthLele you are correct :) – serenskye Nov 01 '12 at 15:14

2 Answers2

1

you can set it on the code behind with setSelectionFromTop

http://developer.android.com/reference/android/widget/ListView.html#setSelectionFromTop(int, int)

I think scrollY is more for scroll view.. I have not tried it on list view from the looks of it I don't think it works in a listview.

I don't think you can scroll from the xml as well if you see the documentation listview xml non inherited attributes are only the following:

android:divider android:dividerHeight android:entries android:footerDividersEnabled android:headerDividersEnabled

I checked AbsListView they don't have attributes that allows you to do that either..

Rejinderi
  • 11,694
  • 2
  • 31
  • 40
0

For this problem You should create a custom scroll bar with the following code.

    <layer-list  xmlns:android="http://schemas.android.com/apk/res/android">
        <item
            android:top="15dp">
            <shape android:shape="rectangle" >                    
                <solid android:color="#421700"/>                     
            </shape>                
        </item>           
    </layer-list>        

set it to the view using attribute

android:scrollbarThumbVertical
Hardik4560
  • 3,202
  • 1
  • 20
  • 31