J
J
jusalex2014-11-06 22:22:54
Android
jusalex, 2014-11-06 22:22:54

How to make smoothScrollToPosition work in ListView more smoothly?

When scrolling the ListView, constantly changing the data in for the adapter

ListData.setListStrings(ListData.getListStringsAll().subList(fromPosition, toPosition));

this way I always have a buffer at the top and bottom of the visible list. To stop the list at the desired position, I use the smoothScrollToPosition method. However, at the same time, an unpleasant jump is observed, but I would like a smooth twist. Similar behavior when using ListView.setSelection().
Is there some way to smoothly scroll the list in my case when the displayed list changes a lot both top and bottom?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Bolloky, 2014-11-07
@Bolloky

There are two approaches. Perhaps they will help you.
1. Try to display the data not immediately, but by placing it in the queue of the UI thread:

public View getView( final int i, final View convertView, final ViewGroup parent ){
    View row;
    if( convertView == null ){
        // creating 
    } else{
        row = convertView;
    }

    final SomeClass idOfDataCell;
    final SomeClass2 data;
    final SomeView dataView = (SomeView)row.findViewById( R.id.id );
    // init idOfDataCell, data
    row.setTag( idOfDataCell );
    row.post( new Runnable (){
        @Override public void run ( ) {
            if( dataView.getTag().equals( idOfDataCell )){
                dataView.setData( data );
            }
        }
    });
    return row;
}

2.Display part of the data after the scroll stops:
SomeAdapter adapter = new SomeAdapter();
listView.setOnScrollListener( new AbsListView.OnScrollListener() {
    @Override
    public void onScrollStateChanged ( AbsListView view,int scrollState ){
        if( scrollState == 2 ){
            realtyListAdapter.scrolling( true );
        } else{
            realtyListAdapter.scrolling( false );
            realtyListAdapter.notifyDataSetChanged();
        }
    }    
} );
listView.setAdapter( adapter );

class SomeAdapter extends BaseAdapter {
    private boolean scrolling;

    public void scrolling( boolean scrolling ){
        this.scrolling = scrolling;
    }

    @Override
    public View getView( final int position, final View convertView, final ViewGroup parent ){
        if( scrolling ) /* отобразить часть данных */;
        else /* отобразить все данные */ ;
        return null;
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question