jess-anders / two-way-gridview

An Android GridView that can be configured to scroll horizontally or vertically
650 stars 261 forks source link

TwoWayGridView.scrollTo(x, y) doesn't work #25

Open jfresen opened 10 years ago

jfresen commented 10 years ago

I have a TwoWayGridView configured to scroll horizontally that I want to scroll programmatically. I tried to call myGridView.scrollTo(0, 0) to see if it scrolls to the beginning of the list, but it doesn't seem to have any effect.

Probably related is that myGridView.getScrollX() and myGridView.getScrollY() always return 0 in the following code:

    final TwoWayGridView myGridView = (TwoWayGridView)view.findViewById(R.id.gridview);
    myGridView.setOnScrollListener(new OnScrollListener() {
        @Override public void onScrollStateChanged(TwoWayAbsListView view, int scrollState) {}
        @Override public void onScroll(TwoWayAbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            myGridView.post(new Runnable() {
                @Override public void run() {
                    Log.i(TAG, "Scrolling to ("+myGridView.getScrollX()+", "+myGridView.getScrollY()+")");
                }
            });
        }
    });
tinasolt commented 9 years ago

i have the same problem, could you solve it?

tinasolt commented 9 years ago

i solve it you have to call grid.setStackFromBottom(true); before setting the adapter for the gird, i hope this will help you too.

jfresen commented 9 years ago

Hi,

I solved it by using grid.smoothScrollBy(distance, time) instead, with distance calculated by my logic and time set to 2000. That worked like a charm.

Kind regards, Jelle