Csabi
Csabi

Reputation: 3043

How to make ListView always scroll to top?

My cutom List View:

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ListView;

public class OverScrollView extends ListView {

    public OverScrollView(Context context) {
        super(context);
        init();
    }

    public OverScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public OverScrollView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init();
    }

    private static int maxOverscroll = 200; 

    @Override
    protected boolean overScrollBy(final int deltaX, final int deltaY, final int scrollX, final int scrollY, final int scrollRangeX, final int scrollRangeY, final int maxOverScrollX, final int maxOverScrollY, final boolean isTouchEvent) {
        return super.overScrollBy(deltaX, deltaY, scrollX, scrollY, scrollRangeX, scrollRangeY, maxOverScrollX, maxOverscroll, isTouchEvent);
    }

    private void init() {
        //maxOverscroll = (int) getContext().getResources().getDisplayMetrics().widthPixels/3;
    }

}

It is custom ListView which is bouncing, the only problem is when Istop the scolling and wait 1 second the release the screen, the whole list view stands still and wont scroll up, or down. How can I make it to scroll to the top or bottom every time it is realesed.

my XML:

<sk.zp.overscroll.scrollView.OverScrollView
    android:id="@+id/list_senders"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/senders_label"
    android:listSelector="@drawable/list_selector"
    android:overScrollMode="always" >
</sk.zp.overscroll.scrollView.OverScrollView>

Upvotes: 3

Views: 1745

Answers (2)

Chintan Rathod
Chintan Rathod

Reputation: 26034

try

lstView.setSelectionAfterHeaderView();

or

lstView.smoothScrollToPosition(0);

Upvotes: 3

Jithu
Jithu

Reputation: 1478

Try this ListView().scrollBy(x, y). I'm not sure

Upvotes: 1

Related Questions