diff options
author | Jason Smith <jason.smith@xamarin.com> | 2016-03-22 13:02:25 -0700 |
---|---|---|
committer | Jason Smith <jason.smith@xamarin.com> | 2016-03-22 16:13:41 -0700 |
commit | 17fdde66d94155fc62a034fa6658995bef6fd6e5 (patch) | |
tree | b5e5073a2a7b15cdbe826faa5c763e270a505729 /Xamarin.Forms.Platform.Android/Renderers/ScrollViewContainer.cs | |
download | xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.tar.gz xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.tar.bz2 xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.zip |
Initial import
Diffstat (limited to 'Xamarin.Forms.Platform.Android/Renderers/ScrollViewContainer.cs')
-rw-r--r-- | Xamarin.Forms.Platform.Android/Renderers/ScrollViewContainer.cs | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/Xamarin.Forms.Platform.Android/Renderers/ScrollViewContainer.cs b/Xamarin.Forms.Platform.Android/Renderers/ScrollViewContainer.cs new file mode 100644 index 00000000..c79e6137 --- /dev/null +++ b/Xamarin.Forms.Platform.Android/Renderers/ScrollViewContainer.cs @@ -0,0 +1,75 @@ +using Android.Content; +using Android.Views; + +namespace Xamarin.Forms.Platform.Android +{ + internal class ScrollViewContainer : ViewGroup + { + readonly ScrollView _parent; + View _childView; + + public ScrollViewContainer(ScrollView parent, Context context) : base(context) + { + _parent = parent; + } + + public View ChildView + { + get { return _childView; } + set + { + if (_childView == value) + return; + + RemoveAllViews(); + + _childView = value; + + if (_childView == null) + return; + + IVisualElementRenderer renderer; + if ((renderer = Platform.GetRenderer(_childView)) == null) + Platform.SetRenderer(_childView, renderer = Platform.CreateRenderer(_childView)); + + if (renderer.ViewGroup.Parent != null) + renderer.ViewGroup.RemoveFromParent(); + + AddView(renderer.ViewGroup); + } + } + + protected override void Dispose(bool disposing) + { + base.Dispose(disposing); + + if (disposing) + { + if (ChildCount > 0) + GetChildAt(0).Dispose(); + RemoveAllViews(); + _childView = null; + } + } + + protected override void OnLayout(bool changed, int left, int top, int right, int bottom) + { + if (_childView == null) + return; + + IVisualElementRenderer renderer = Platform.GetRenderer(_childView); + renderer.UpdateLayout(); + } + + protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec) + { + // we need to make sure we are big enough to be laid out at 0,0 + if (_childView != null) + { + SetMeasuredDimension((int)Context.ToPixels(_childView.Bounds.Right + _parent.Padding.Right), (int)Context.ToPixels(_childView.Bounds.Bottom + _parent.Padding.Bottom)); + } + else + SetMeasuredDimension((int)Context.ToPixels(_parent.Padding.Right), (int)Context.ToPixels(_parent.Padding.Bottom)); + } + } +}
\ No newline at end of file |