2

I wanna when listview 1 is scrolled by user, listview 2 also is scroll like listview 1 (exactly in pixel).
I tried to scroll listview 2 by smoothScrollByOffset(offset),
but it scrolls more than listview 1.
I dont know why?
What happened with smoothScrollByOffset(offset) or I miss something?

Further information:
Code to scroll listview 2 (in onScroll callback of listview 1):

    int previsous = 0;
    public void onScroll(AbsListView view, int firstVisibleItem,
            int visibleItemCount, int totalItemCount) {
        //get current position in pixel of listview 1 
        View c = lv1.getChildAt(0);
        int scrolly = -c.getTop() + lv1.getFirstVisiblePosition() * c.getHeight();
        //Difference in pixel with the last scroll
        int delta = scrolly - previsous;
        Log.d("scroll", "listview 1 has scrolled: " + 
                scrolly + "| Difference with the last " + delta);

        //scroll listview 2 by delta
        lv2.smoothScrollByOffset(delta);
        previsous = scrolly;
    }

Screen shot for diagnostic:
enter image description here

tana
  • 585
  • 1
  • 5
  • 16

2 Answers2

0

Try to use smoothScrollToPosition (int position) instead of smoothScrollByOffset (int offset), I hope this will help you, Let me know what happened.

Gunaseelan
  • 14,415
  • 11
  • 80
  • 128
  • smoothScrollToPosition (int position) is not comfortable in my case. Because it is position of item, it scroll by item not by pixel. So that makes a difference in item break line of listview 1 and 2 when user scroll (I wanna these item break line must be same line). You can imaging that's although there is 2 listview, in user's view these must be 1 listview. – tana Apr 18 '14 at 10:35
  • Okay! Can you take a look on [this](http://stackoverflow.com/questions/13952357/infinite-auto-scroll-listview-with-scroll-speed-controlled/14070683#14070683) answer for timer. – Gunaseelan Apr 18 '14 at 10:37
  • [simple timer example in android](http://v4all123.blogspot.in/2013/01/timer.html) – Gunaseelan Apr 18 '14 at 10:44
  • maybe I make you're confused by using "faster", that relates to speed. So you suggest solution with timer to control speed of scroll. The problem is listview 2 is scrolled more than listview 1 (smoothScrollByOffset(offset) not works as my expected). – tana Apr 18 '14 at 10:58
0

You are using the wrong method. The smoothScrollByOffset() doesn't accept pixels, but number of positions. Use smoothScrollBy(int distance, int duration)

Miloš Černilovský
  • 3,846
  • 1
  • 28
  • 30