public static Bitmap ToBitmap(this AView view) { var layout = new FrameLayout(view.Context); layout.LayoutParameters = new FrameLayout.LayoutParams(500, 500); view.LayoutParameters = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WrapContent, FrameLayout.LayoutParams.WrapContent) { Gravity = GravityFlags.Center }; layout.AddView(view); layout.Measure(500, 500); layout.Layout(0, 0, 500, 500); var act = view.Context.GetActivity(); var rootView = act.FindViewById <FrameLayout>(Android.Resource.Id.Content); rootView.AddView(layout); var bitmap = Bitmap.CreateBitmap(view.Width, view.Height, Bitmap.Config.Argb8888); Canvas canvas = new Canvas(bitmap); view.Layout(0, 0, view.Width, view.Height); view.Draw(canvas); rootView.RemoveView(layout); return(bitmap); }
public static async Task <T> AttachAndRun <T>(this AView view, Func <T> action) { var layout = new FrameLayout(view.Context); layout.LayoutParameters = new FrameLayout.LayoutParams(500, 500); view.LayoutParameters = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WrapContent, FrameLayout.LayoutParams.WrapContent) { Gravity = GravityFlags.Center }; var act = view.Context.GetActivity(); var rootView = act.FindViewById <FrameLayout>(Android.Resource.Id.Content); rootView.AddView(layout); layout.AddView(view); layout.Measure(500, 500); layout.Layout(0, 0, 500, 500); await Task.Delay(100); try { var result = action(); return(result); } finally { rootView.RemoveView(layout); layout.RemoveView(view); } }
protected override void OnLayout(bool changed, int l, int t, int r, int b) { surfaceViewPlaceholder.Measure( MeasureSpec.MakeMeasureSpec(r - l, MeasureSpecMode.Exactly), MeasureSpec.MakeMeasureSpec(b - t, MeasureSpecMode.Exactly)); surfaceViewPlaceholder.Layout(0, 0, r - l, b - t); }
protected override void OnLayout(bool changed, int l, int t, int r, int b) { base.OnLayout(changed, l, t, r, b); if (nativeView != null) { var msw = MeasureSpec.MakeMeasureSpec(r - l, MeasureSpecMode.Exactly); var msh = MeasureSpec.MakeMeasureSpec(b - t, MeasureSpecMode.Exactly); nativeView.Measure(msw, msh); nativeView.Layout(0, 0, r - l, b - t); } }
// Because FastRenderer of Label or Image can't be set ClickListener, // insert FrameLayout with same position and same size on the view. public void OnLayoutChange(Android.Views.View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { _overlay.Layout(v.Left, v.Top, v.Right, v.Bottom); if (_alreadyGotParent) { return; } _parent = _effect.Control.Parent as Android.Views.ViewGroup; _alreadyGotParent = true; _parent.AddView(_overlay); _overlay.BringToFront(); _effect._view.Touch -= _effect._view_Touch; _effect._view = _overlay; _effect.UpdateEnableRipple(); }
public static Bitmap ToBitmap(this AView view) { var layout = new FrameLayout(view.Context); layout.LayoutParameters = new FrameLayout.LayoutParams(500, 500); view.LayoutParameters = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WrapContent, FrameLayout.LayoutParams.WrapContent) { Gravity = GravityFlags.Center }; layout.AddView(view); layout.Measure(500, 500); layout.Layout(0, 0, 500, 500); var bitmap = Bitmap.CreateBitmap(view.Width, view.Height, Bitmap.Config.Argb8888); Canvas canvas = new Canvas(bitmap); view.Layout(0, 0, view.Width, view.Height); view.Draw(canvas); return(bitmap); }
protected override void OnLayout(bool changed, int l, int t, int r, int b) { int width = r - l; int height = b - t; if (width > 0 && height > 0) { var context = Context; _rootLayout.Measure(MeasureSpecFactory.MakeMeasureSpec(width, MeasureSpecMode.AtMost), MeasureSpecFactory.MakeMeasureSpec(height, MeasureSpecMode.AtMost)); _rootLayout.Layout(0, 0, _rootLayout.MeasuredWidth, _rootLayout.MeasuredHeight); _bottomBar.Measure(MeasureSpecFactory.MakeMeasureSpec(width, MeasureSpecMode.Exactly), MeasureSpecFactory.MakeMeasureSpec(height, MeasureSpecMode.AtMost)); int tabsHeight = BottomBarHeight.HasValue ? (int)Context.ToPixels(BottomBarHeight.Value) : Math.Min(height, Math.Max(_bottomBar.MeasuredHeight, _bottomBar.MinimumHeight)); _frameLayout.Layout(0, 0, width, height - tabsHeight); _pageController.ContainerArea = new Rectangle(0, 0, context.FromPixels(width), context.FromPixels(_frameLayout.Height)); _bottomBar.Layout(0, height - tabsHeight, width, height); } base.OnLayout(changed, l, t, r, b); }