Closed midhun3112 closed 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.
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).
@ksoichiro Can you please explain how we can do if we get the exact height of the new view :)
@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.
@ksoichiro Thanks for the reply. I will try and let you know :+1:
@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.
@KapilKrishnankutty your implements sounds interesting. could you please post your calculation and your implement in listview and your adapter here?
@ksoichiro @eneim
https://gist.github.com/KapilKrishnankutty/36117a5d2bced77bc693
Please check
@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.
@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
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.
@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:
@midhunQburst Can u please post some sample.
@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.