HorizontalVariableListView icon indicating copy to clipboard operation
HorizontalVariableListView copied to clipboard

Question: smoothScrollTo?

Open toufoo opened this issue 12 years ago • 11 comments

Could you please add smoothScrollTo method in your Demo code?

I changed the followings in your demo code:

  1. change item width to 100px in view1.xml
  2. I want to scroll to the 31th item, so in the MainActivity.java added the following line at the end of onCreate method, then the scroll bar is empty now.

mList.smoothScrollTo(30*100);

toufoo avatar Apr 26 '13 18:04 toufoo

I tried something similar and it looks like it's not working as expected. I tried smooth scrolling to item 132 in my list but it actually goes to item 98 (all items are the same width of 100px) and the scroll actually doesn't happen. It seems to get stuck on item 0 and then all of a sudden it shows item 98 and surroundings.

tanis2000 avatar May 22 '13 15:05 tanis2000

you must smoothScroll with the amount of pixels to scroll, not the item you want to show. ps. are you using the "development" branch?

sephiroth74 avatar May 22 '13 15:05 sephiroth74

I'm calling it like

mList.scrollTo(index*100);

where index is the position and 100 is the width of the item view in pixels.

I'm using the master branch.

tanis2000 avatar May 22 '13 15:05 tanis2000

Try switching to the development branch. It works there. Btw I will update the demo app also On May 22, 2013 11:51 AM, "Valerio Santinelli" [email protected] wrote:

I'm calling it like

mList.scrollTo(index*100);

where index is the position and 100 is the width of the item view in pixels.

I'm using the master branch.

— Reply to this email directly or view it on GitHubhttps://github.com/sephiroth74/HorizontalVariableListView/issues/9#issuecomment-18287899 .

sephiroth74 avatar May 22 '13 15:05 sephiroth74

The development branch doesn't even scroll close to the position now. It looks like it's not scrolling at all as it's stuck in position 0.

tanis2000 avatar May 22 '13 16:05 tanis2000

try to fetch again the dev branch, then in the MainActivity replace this code:

line 387: adapter.replace( last, getNextValue() );

with this: mList.smoothScrollTo( mList.getChildAt( 0 ).getWidth() * 10 );

the list will scroll to the 11° element

sephiroth74 avatar May 22 '13 17:05 sephiroth74

Ok, I just tried what you suggested, but it crashes with the following error:

05-24 10:12:53.038      918-918/it.sephiroth.android.sample.horizontalvariablelistviewdemo E/AndroidRuntime: FATAL EXCEPTION: main
        java.lang.NoSuchMethodError: it.sephiroth.android.library.widget.HorizontalVariableListView.postInvalidateOnAnimation
        at it.sephiroth.android.library.widget.HorizontalVariableListView.smoothScrollBy(HorizontalVariableListView.java:2255)
        at it.sephiroth.android.library.widget.HorizontalVariableListView.smoothScrollTo(HorizontalVariableListView.java:2241)
        at it.sephiroth.android.sample.horizontalvariablelistviewdemo.MainActivity.onClick(MainActivity.java:387)
        at android.view.View.performClick(View.java:3540)
        at android.view.View$PerformClick.run(View.java:14167)
        at android.os.Handler.handleCallback(Handler.java:605)
        at android.os.Handler.dispatchMessage(Handler.java:92)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:4560)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
        at dalvik.system.NativeStart.main(Native Method)

tanis2000 avatar May 24 '13 08:05 tanis2000

ok, fixed it. btw just change that into postInvalidate() instead

sephiroth74 avatar May 24 '13 12:05 sephiroth74

Yes, it works this way. I'm going to try and bring the dev branch into my project and see if it works there as well ;) Thanks!

tanis2000 avatar May 24 '13 15:05 tanis2000

I tried with around 200 items in the scrollview and it hangs there for some seconds and then it doesn't scroll. But if I touch the view, it scrolls but not in the correct position.

I tried with scrollTo() instead, but it's pretty much the same.

Have you got any suggestion of what method I could use to just jump to a certain position?

tanis2000 avatar May 24 '13 15:05 tanis2000

yeah, the problem is that the list cannot scroll for more than its width within a single frame... I've added a temporary solution, checkout the latest developement branch. I've added also a demo in the MainActivity. But a better solution should be found on this.

sephiroth74 avatar May 27 '13 15:05 sephiroth74