ksoichiro / Android-ObservableScrollView

Android library to observe scroll events on scrollable views.
http://ksoichiro.github.io/Android-ObservableScrollView/
Apache License 2.0
9.66k stars 2.06k forks source link

Incorrect scrollY while dynamically show/hide some views in list item.(For expand collapse functionality) #154

Closed midhun3112 closed 9 years ago

midhun3112 commented 9 years ago

@ksoichiro First of all I started my code by looking at the sample (https://github.com/ksoichiro/Android-ObservableScrollView/blob/master/samples/src/main/java/com/github/ksoichiro/android/observablescrollview/samples/FlexibleSpaceWithImageListViewActivity.java). Everything works perfect if we don't do any dynamic update on listview item. But when I show/hide some views on listview item the particular list item height increases and the overall height of listview also increases. In such cases the scrollY returned is wrong sometimes. We are calling listview.requestLayout() after show/hide. But then also the same error in ScrollY occurs.

KapilKrishnankutty commented 9 years ago

@ksoichiro I am also facing the same issue and has been trying out many options. But nothing worked so far. Please help.

ksoichiro commented 9 years ago

Thanks for your report.

I'm sorry but I think It's hard to handle it with the current design.

ObservableListView calculates its scroll position with the scrolled children height (sum of the height of the child views which has already been scrolled), so when the height of the children changes dynamically scrollY will become incorrect.

However, if you can get exact height of the updated view (old height and new height), perhaps it might be possible (with some modifications to the library).

midhun3112 commented 9 years ago

@ksoichiro Can you please explain how we can do if we get the exact height of the new view :)

ksoichiro commented 9 years ago

@midhunQburst ObservableListView has an internal variable mPrevScrolledChildrenHeight to keep children views' height, and scrollY is determined with mPrevScrolledChildrenHeight - firstVisibleChild.getTop(). So if you know the changed height (new height - old height), you can adjust mPrevScrolledChildrenHeight so that scrollY indicates the correct value. (To do this, of course we need to add new API to the library to adjust mPrevScrolledChildrenHeight as I mentioned above.)

This is just an idea. I haven't tried so I'm not sure it's correct.

midhun3112 commented 9 years ago

@ksoichiro Thanks for the reply. I will try and let you know :+1:

KapilKrishnankutty commented 9 years ago

@ksoichiro First of all thank you for your reply.

My case is like I am adding some additional views to listview row on clicking the row. Now the height of the view is increased. I am getting this increased height in onScrollchanged() and I tried to keep the height before adding new views and after adding new views. And then if the difference for this is greater I am adding that difference to mPrevScrolledChildrenHeight. When I click the item..it is working as expected. Now when I scroll I am again getting into trouble. The listview recycles and this causes issue. My calculation breaks here. How to handle this situation. Can you please help. I am trying out many things for some days now.

eneim commented 9 years ago

@KapilKrishnankutty your implements sounds interesting. could you please post your calculation and your implement in listview and your adapter here?

KapilKrishnankutty commented 9 years ago

@ksoichiro @eneim
https://gist.github.com/KapilKrishnankutty/36117a5d2bced77bc693

Please check

midhun3112 commented 9 years ago

@ksoichiro @eneim I am also stuck with this issue. If the list item is not opened then the scrolling works without any issues. But if the list item is opened then the scrollY becomes wrong.

eneim commented 9 years ago

@midhunQburst please give my library a try. It's inspired by many ideas including AOSL repo. I borrow @ksoichiro some snippets too (fully credited). Sample code is as follow, and you can checkout my sample app for more details. If it works for you, I will compare the code base and create a pull request to @ksoichiro

https://github.com/eneim/ObservableScrollers/blob/master/app/src/main/java/im/ene/lab/obervablescrollers/sample/ui/ObsListViewFlexibleSpaceWithImageActivity.java

Click the text to trigger a hidden/shown view to be shown/hidden.

Disclaimer: My library is under development, and I create it for fun/studying only. No release ETA and AOSL should be your choice for long term.

midhun3112 commented 9 years ago

@eneim @ksoichiro I fixed this issue by using verticaloffset returned by the listview instead of scrollY in ObservableListVIew. Thanks for helping me solve this issue. :+1:

rishabhsri20 commented 8 years ago

@midhunQburst Can u please post some sample.