开发者

how can move scroll bar automatically?

开发者 https://www.devze.com 2023-01-15 18:16 出处:网络
I am using grid view for display images, I want to scroll开发者_StackOverflow move automatically, whenever I add another images in gridview, is it possible?I think you have to read a little bit more :

I am using grid view for display images, I want to scroll开发者_StackOverflow move automatically, whenever I add another images in gridview, is it possible?


I think you have to read a little bit more :

https://developer.android.com/reference/android/widget/AdapterView.html#setSelection(int)

ListView.setSelection(position);

https://developer.android.com/reference/android/widget/AbsListView.html#smoothScrollToPosition(int)

ListView.smoothScrollToPosition(position).


Either call setSelection() or use smoothScrollToPosition().


I got result using GridView.setSelection(GridView.getCount()),so scroll bar automatically move to last element of Grid View


Use TimerTask to do that since Adapter.notifyDataSetChanged() takes delay to update the grid or list. Code is below:

new Timer().schedule(new TimerTask()
            {
                @Override
                public void run() {         
                    nameHandler.sendEmptyMessage(0);
                }
            },500);
//// And in handler::

Handler nameHandler = new Handler()
    {
        public void handleMessage(Message msg)
        {
            super.handleMessage(msg);
            gridView.setSelection(selectorIndex);
                         // OR
            gridView.smoothScrollToPosition(selectorIndex);
            gridView.invalidate();
        }
    } ;
0

精彩评论

暂无评论...
验证码 换一张
取 消