protected override void OnLayout(bool changed, int l, int t, int r, int b) { base.OnLayout(changed, l, t, r, b); relativeLayout.Layout(0, 0, r, b); topTextView.Layout(0, 25, r, 65); var mswBP = MeasureSpec.MakeMeasureSpec(r - l, MeasureSpecMode.Exactly); var mshBP = MeasureSpec.MakeMeasureSpec(b - t, MeasureSpecMode.Exactly); barcodePicker.Measure(mswBP, mshBP); barcodePicker.Layout(0, 90, r - l, b - t); overlay.Layout(0, ((b / 2) + 40), r - l, b); bottomTextView.Layout(0, (b / 2) + 60, r - l, b - 100); qrImageView.Layout(0, (b / 2) + 100, r - l, b - 20); }
protected override void OnLayout(bool changed, int l, int t, int r, int b) { base.OnLayout(changed, l, t, r, b); if (!changed) { return; } try { var msw1 = MeasureSpec.MakeMeasureSpec(r, MeasureSpecMode.Exactly); var msh1 = MeasureSpec.MakeMeasureSpec(b, MeasureSpecMode.Exactly); mainLayout.Measure(msw1, msh1); mainLayout.Layout(l, t, r, b); if (mainLayout.Width < mainLayout.Height) { if (camera != null) { camera.SetDisplayOrientation(90); } int tmpPr = (mainLayout.Width / 100) * 10; capturePhotoButtonSatart.SetX(mainLayout.Width / 2 + tmpPr); capturePhotoButtonSatart.SetY(mainLayout.Height - 200); capturePhotoButtonStop.SetX(mainLayout.Width / 2 + tmpPr); capturePhotoButtonStop.SetY(mainLayout.Height - 200); } else { if (camera != null) { camera.SetDisplayOrientation(0); } int tmpPr = (mainLayout.Width / 100) * 10; capturePhotoButtonSatart.SetY(mainLayout.Height / 2 + tmpPr); capturePhotoButtonSatart.SetX(mainLayout.Width - 200); capturePhotoButtonStop.SetY(mainLayout.Height / 2 + tmpPr); capturePhotoButtonStop.SetX(mainLayout.Width - 200); } } catch (NullReferenceException) { } }
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); _bottomNavigationView.Measure(MeasureSpecFactory.MakeMeasureSpec(width, MeasureSpecMode.Exactly), MeasureSpecFactory.MakeMeasureSpec(height, MeasureSpecMode.AtMost)); int tabsHeight = System.Math.Min(height, System.Math.Max(_bottomNavigationView.MeasuredHeight, _bottomNavigationView.MinimumHeight)); _frameLayout.Layout(0, 0, width, height - tabsHeight); _pageController.ContainerArea = new Rectangle(0, 0, context.FromPixels(width), context.FromPixels(_frameLayout.Height)); _bottomNavigationView.Layout(0, height - tabsHeight, width, height); } base.OnLayout(changed, l, t, r, b); }
protected override void OnLayout(bool changed, int l, int t, int r, int b) { FormsViewPager pager = _viewPager; Context context = Context; var width = r - l; var height = b - t; if (IsBottomTabPlacement) { if (width <= 0 || height <= 0) { return; } _relativeLayout.Measure( MeasureSpec.MakeMeasureSpec(width, MeasureSpecMode.Exactly), MeasureSpec.MakeMeasureSpec(height, MeasureSpecMode.Exactly)); pager.Measure(MeasureSpecFactory.MakeMeasureSpec(width, MeasureSpecMode.AtMost), MeasureSpecFactory.MakeMeasureSpec(height, MeasureSpecMode.AtMost)); if (width > 0 && height > 0) { PageController.ContainerArea = new Rectangle(0, 0, context.FromPixels(width), context.FromPixels(height - _bottomNavigationView.MeasuredHeight)); SetNavigationRendererPadding(0, _bottomNavigationView.MeasuredHeight); pager.Layout(0, 0, width, b); // We need to measure again to ensure that the tabs show up _relativeLayout.Measure( MeasureSpec.MakeMeasureSpec(width, MeasureSpecMode.Exactly), MeasureSpec.MakeMeasureSpec(height, MeasureSpecMode.Exactly)); _relativeLayout.Layout(0, 0, _relativeLayout.MeasuredWidth, _relativeLayout.MeasuredHeight); } } else { TabLayout tabs = _tabLayout; tabs.Measure(MeasureSpecFactory.MakeMeasureSpec(width, MeasureSpecMode.Exactly), MeasureSpecFactory.MakeMeasureSpec(height, MeasureSpecMode.AtMost)); var tabsHeight = 0; if (tabs.Visibility != ViewStates.Gone) { //MinimumHeight is only available on API 16+ if ((int)Build.VERSION.SdkInt >= 16) { tabsHeight = Math.Min(height, Math.Max(tabs.MeasuredHeight, tabs.MinimumHeight)); } else { tabsHeight = Math.Min(height, tabs.MeasuredHeight); } } pager.Measure(MeasureSpecFactory.MakeMeasureSpec(width, MeasureSpecMode.AtMost), MeasureSpecFactory.MakeMeasureSpec(height, MeasureSpecMode.AtMost)); if (width > 0 && height > 0) { PageController.ContainerArea = new Rectangle(0, context.FromPixels(tabsHeight), context.FromPixels(width), context.FromPixels(height - tabsHeight)); SetNavigationRendererPadding(tabsHeight, 0); pager.Layout(0, 0, width, b); // We need to measure again to ensure that the tabs show up tabs.Measure(MeasureSpecFactory.MakeMeasureSpec(width, MeasureSpecMode.Exactly), MeasureSpecFactory.MakeMeasureSpec(tabsHeight, MeasureSpecMode.Exactly)); tabs.Layout(0, 0, width, tabsHeight); UpdateTabBarTranslation(pager.CurrentItem, 0); } } base.OnLayout(changed, l, t, r, b); }
public Bitmap createBitmapFromLayoutWithText(Pin pin, float steps, int currentEmojiIndex) { var inflater = Android.App.Application.Context.GetSystemService(Context.LayoutInflaterService) as Android.Views.LayoutInflater; Android.Widget.RelativeLayout view = new Android.Widget.RelativeLayout(Context); inflater.Inflate(Resource.Layout.XamarinMapInfoWindow, view, true); if (customMap.OnSelect) { view.Measure(MeasureSpec.MakeMeasureSpec(0, Android.Views.MeasureSpecMode.Unspecified), MeasureSpec.MakeMeasureSpec(0, Android.Views.MeasureSpecMode.Unspecified)); view.Layout(0, 0, view.MeasuredWidth, view.MeasuredHeight); Bitmap bitmap = Bitmap.CreateBitmap(view.MeasuredWidth, view.MeasuredHeight, Bitmap.Config.Argb8888); Canvas c = new Canvas(bitmap); view.Draw(c); c.Dispose(); return(bitmap); } else { //var emoji1 = view.FindViewById<TextView>(Resource.Id.Emoji); //var cpin = pin as PinModel; //switch (currentEmojiIndex) //{ // case (0): // if (cpin.Emojis.Count > 0) // { // emoji1.Text = cpin.Emojis[0]; // emoji1.TextSize = 25; // emoji1.TranslationY = -steps; // } // break; // case (1): // if (cpin.Emojis.Count > 0) // { // emoji1.Text = cpin.Emojis[1]; // emoji1.TextSize = 25; // emoji1.TranslationY = -steps; // } // break; // case (2): // if (cpin.Emojis.Count > 1) // { // emoji1.Text = cpin.Emojis[2]; // emoji1.TextSize = 25; // emoji1.TranslationY = -steps; // } // break; // case (3): // if (cpin.Emojis.Count > 2) // { // emoji1.Text = cpin.Emojis[3]; // emoji1.TextSize = 25; // emoji1.TranslationY = -steps; // } // break; //} view.Measure(MeasureSpec.MakeMeasureSpec(0, Android.Views.MeasureSpecMode.Unspecified), MeasureSpec.MakeMeasureSpec(0, Android.Views.MeasureSpecMode.Unspecified)); view.Layout(0, 0, view.MeasuredWidth, view.MeasuredHeight); Bitmap bitmap = Bitmap.CreateBitmap(view.MeasuredWidth, view.MeasuredHeight, Bitmap.Config.Argb8888); Canvas c = new Canvas(bitmap); view.Draw(c); c.Dispose(); view.Dispose(); return(bitmap); } }
public Bitmap DrawPin(Pin p, float step, int currentEmojiIndex, float x) { BitmapFactory.Options options = new BitmapFactory.Options { InJustDecodeBounds = true, InScaled = true, InMutable = true, }; Bitmap b = BitmapFactory.DecodeResource(Resources, Resource.Id.pin, options); options.InJustDecodeBounds = false; try { if (customMap.OnSelect) { var inflater = Android.App.Application.Context.GetSystemService(Context.LayoutInflaterService) as Android.Views.LayoutInflater; Android.Widget.RelativeLayout view = new Android.Widget.RelativeLayout(Context); inflater.Inflate(Resource.Layout.XamarinMapInfoWindow, view, true); view.Measure(MeasureSpec.MakeMeasureSpec(0, Android.Views.MeasureSpecMode.Unspecified), MeasureSpec.MakeMeasureSpec(0, Android.Views.MeasureSpecMode.Unspecified)); view.Layout(0, 0, view.MeasuredWidth, view.MeasuredHeight); Bitmap bitmap = Bitmap.CreateBitmap(view.MeasuredWidth, view.MeasuredHeight, Bitmap.Config.Alpha8); Canvas c = new Canvas(bitmap); view.Draw(c); c.Dispose(); return(bitmap); } else { System.Diagnostics.Debug.WriteLine("Step: {0}", step); b = Bitmap.CreateBitmap(75, 280, Bitmap.Config.Argb8888); Canvas canvas = new Canvas(b); Rect bounds = new Rect(); Paint paint = new Paint(PaintFlags.AntiAlias); paint.TextSize = (float)(50 * App.scale); float startY = (float)(170 * App.scale); string emoji = ""; var pinModel = p as PinModel; if (pinModel != null && pinModel.Emojis.Count > 0) { emoji = pinModel.Emojis[currentEmojiIndex]; } var rand = new Random(); canvas.DrawText(emoji, x, startY * (1 - step), paint); canvas.Dispose(); paint.Dispose(); //int numEmojis = (int)Math.Ceiling( step / 0.25f ); //System.Diagnostics.Debug.WriteLine("Number of emojis to show: {0}", numEmojis); //for (int n = 0; n < numEmojis; n++) { // string emoji = ":)"; // var pinModel = p as PinModel; // if (pinModel != null && pinModel.Emojis.Count > 0) // { // emoji = pinModel.Emojis[numEmojis - n - 1]; // } // float y = (300 - 35) * (1 - n * (step - 0.25f)); // System.Diagnostics.Debug.WriteLine("y = {0}", y); // canvas.DrawText(emoji, 17, y, paint); //} } } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Exception: {0}", e.Message); if (b != null) { b.Recycle(); b.Dispose(); b = null; } } return(b); }