private void OrganiseForegroundView(View foreground)
{
var insertPos = ChildCount - 1;
if (foreground is ObservableScrollView)
{
_scrollView = (ObservableScrollView)foreground;
_scrollView.ScrollChanged -= ScrollViewOnScrollChanged;
}
else if (foreground is ViewGroup && !(foreground is ScrollView))
{
_scrollView = new ObservableScrollView(Context, null);
RemoveView(foreground);
_scrollView.AddView(foreground);
AddView(_scrollView, insertPos);
}
else if (foreground is ScrollView)
{
var child = ((ScrollView) foreground).ChildCount > 0 ?
((ScrollView) foreground).GetChildAt(0) : null;
_scrollView = new ObservableScrollView(Context, null);
RemoveView(foreground);
if (child != null)
_scrollView.AddView(child);
AddView(_scrollView, insertPos);
}
else
{
_scrollView = new ObservableScrollView(Context, null);
RemoveView(foreground);
_scrollView.AddView(foreground);
AddView(_scrollView, insertPos);
}
if (_scrollView != null)
{
_scrollView.LayoutParameters = foreground.LayoutParameters;
_scrollView.ScrollChanged += ScrollViewOnScrollChanged;
_scrollView.FillViewport = true;
}
}