How to synchronize content of one view depending o

2019-07-20 17:33发布

问题:

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.