How to synchronize content of one view depending on scroll position in sibling ScrollView?

人走茶凉 提交于 2019-12-11 01:19:00

问题


I have extended LinearLayout (vertical) to create a custom compound component. This in turn contains two children:

  • one custom view that is drawn directly onto the view canvas.
  • one HorizontalScrollView->LinearView(Horizontal)->Multiple custom views.

I would now like to redraw the custom view to match the visible contents of the scroll view. The reason for this is that the long array of custom components in the scroll view are mainly static and suitable to be drawn ahead of time, while the top view is supposed to be highly dynamic and relate to whatever things are visible in the scroll view.

I hope I made the problem/idea somewhat clear. I am not att all confident this is the best approach, and I'd enjoy hearing any suggestions on alternative solutions or perhaps some idea on how to trigger a redraw-event everytime the scroll position changes in the HorizontalScrollView.

Thank!


回答1:


You can have your activity listen to the scroll view adapter. in the adapter when ever the scroll position changes you execute the delegate in the Activity. That way the activity can update the rest of the views upon scroll view change.



来源:https://stackoverflow.com/questions/1635699/how-to-synchronize-content-of-one-view-depending-on-scroll-position-in-sibling-s

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!