public HomePage () { InitializeComponent (); #if __IOS__ const string originalText = "Native UILabel."; const string longerText = "Native UILabel. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut vel elit orci. Nam sollicitudin consectetur congue."; var uiLabel = new UILabel { MinimumFontSize = 14f, Lines = 0, LineBreakMode = UILineBreakMode.WordWrap, Text = originalText, }; stackLayout.Children.Add (uiLabel); var uiButton = new UIButton (UIButtonType.RoundedRect); uiButton.SetTitle ("Change Text", UIControlState.Normal); uiButton.Font = UIFont.FromName ("Helvetica", 14f); uiButton.TouchUpInside += (sender, args) => { uiLabel.Text = uiLabel.Text == originalText ? longerText : originalText; uiLabel.SizeToFit (); }; stackLayout.Children.Add (uiButton); var explanation1 = new UILabel { MinimumFontSize = 14f, Lines = 0, LineBreakMode = UILineBreakMode.WordWrap, Text = "The next control is a CustomControl (a customized UILabel with a bad SizeThatFits implementation).", }; stackLayout.Children.Add (explanation1); var brokenControl = new CustomControl { MinimumFontSize = 14, Lines = 0, LineBreakMode = UILineBreakMode.WordWrap, Text = "This control has incorrect sizing - there's empty space above and below it." }; stackLayout.Children.Add (brokenControl); var explanation2 = new UILabel { MinimumFontSize = 14f, Lines = 0, LineBreakMode = UILineBreakMode.WordWrap, Text = "The next control is a CustomControl, but an override to the GetDesiredSize method is passed in when adding the control to the layout.", }; stackLayout.Children.Add (explanation2); var fixedControl = new CustomControl { MinimumFontSize = 14, Lines = 0, LineBreakMode = UILineBreakMode.WordWrap, Text = "This control has correct sizing - there's no empty space above and below it." }; stackLayout.Children.Add (fixedControl, FixSize); #endif #if __ANDROID__ const string originalText = "Native TextView."; const string longerText = "Native TextView. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut vel elit orci. Nam sollicitudin consectetur congue."; var textView = new TextView (Forms.Context) { Text = originalText, TextSize = 14 }; textView.SetSingleLine (false); textView.SetLines (3); stackLayout.Children.Add (textView); var button = new Android.Widget.Button (Forms.Context) { Text = "Change Text" }; button.Click += (sender, args) => { textView.Text = textView.Text == originalText ? longerText : originalText; }; stackLayout.Children.Add (button); var explanation1 = new TextView (Forms.Context) { Text = "The next control is a CustomControl (a customized TextView with a bad OnMeasure implementation).", TextSize = 14 }; stackLayout.Children.Add (explanation1); var brokenControl = new CustomControl (Forms.Context) { Text = "This control has incorrect sizing - it doesn't occupy the available width of the device.", TextSize = 14 }; stackLayout.Children.Add (brokenControl); var explanation2 = new TextView (Forms.Context) { Text = "The next control is a CustomControl, but with a custom GetDesiredSize delegate to accomodate it's sizing problem.", TextSize = 14 }; stackLayout.Children.Add (explanation2); var goodControl = new CustomControl (Forms.Context) { Text = "This control has correct sizing - it occupies the available width of the device.", TextSize = 14 }; stackLayout.Children.Add (goodControl, FixSize); #endif #if WINDOWS_PHONE_APP const string originalText = "Native TextBlock."; const string longerText = "Native TextBlock. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut vel elit orci. Nam sollicitudin consectetur congue."; var textBlock = new TextBlock { Text = originalText, FontSize = 14, FontFamily = new FontFamily("HelveticaNeue"), TextWrapping = TextWrapping.Wrap }; stackLayout.Children.Add(textBlock); var button = new Windows.UI.Xaml.Controls.Button { Content = "Change Text" }; button.Click += (sender, args) => { textBlock.Text = textBlock.Text == originalText ? longerText : originalText; }; stackLayout.Children.Add(button); var explanation1 = new TextBlock { Text = "The next control is a CustomControl (a customized TextBlock with a bad ArrangeOverride implementation).", FontSize = 14, FontFamily = new FontFamily("HelveticaNeue"), TextWrapping = TextWrapping.Wrap }; stackLayout.Children.Add(explanation1); var brokenControl = new CustomControl { Text = "This control has incorrect sizing - it doesn't occupy the available width of the device." }; stackLayout.Children.Add(brokenControl); var explanation2 = new TextBlock { Text = "The next control is a CustomControl, but an ArrangeOverride delegate is passed in when adding the control to the layout.", FontSize = 14, FontFamily = new FontFamily("HelveticaNeue"), TextWrapping = TextWrapping.Wrap }; stackLayout.Children.Add(explanation2); var fixedControl = new CustomControl { Text = "This control has correct sizing - it occupies the available width of the device." }; stackLayout.Children.Add(fixedControl, arrangeOverrideDelegate: (renderer, finalSize) => { if (finalSize.Width <= 0 || double.IsInfinity(finalSize.Width)) { return null; } var frameworkElement = renderer.Control; frameworkElement.Arrange(new Rect(0, 0, finalSize.Width * 2, finalSize.Height)); return finalSize; }); #endif #if WINDOWS_UWP const string originalText = "Native TextBlock."; const string longerText = "Native TextBlock. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut vel elit orci. Nam sollicitudin consectetur congue."; var textBlock = new TextBlock { Text = originalText, FontSize = 14, FontFamily = new FontFamily("HelveticaNeue"), TextWrapping = TextWrapping.Wrap }; stackLayout.Children.Add(textBlock); var button = new Windows.UI.Xaml.Controls.Button { Content = "Change Text" }; button.Click += (sender, args) => { textBlock.Text = textBlock.Text == originalText ? longerText : originalText; }; stackLayout.Children.Add(button); var explanation1 = new TextBlock { Text = "The next control is a CustomControl (a customized TextBlock with a bad ArrangeOverride implementation).", FontSize = 14, FontFamily = new FontFamily("HelveticaNeue"), TextWrapping = TextWrapping.Wrap }; stackLayout.Children.Add(explanation1); var brokenControl = new CustomControl { Text = "This control has incorrect sizing - it doesn't occupy the available width of the device." }; stackLayout.Children.Add(brokenControl); var explanation2 = new TextBlock { Text = "The next control is a CustomControl, but an ArrangeOverride delegate is passed in when adding the control to the layout.", FontSize = 14, FontFamily = new FontFamily("HelveticaNeue"), TextWrapping = TextWrapping.Wrap }; stackLayout.Children.Add(explanation2); var fixedControl = new CustomControl { Text = "This control has correct sizing - it occupies the available width of the device." }; stackLayout.Children.Add(fixedControl, arrangeOverrideDelegate: (renderer, finalSize) => { if (finalSize.Width <= 0 || double.IsInfinity(finalSize.Width)) { return null; } var frameworkElement = renderer.Control; frameworkElement.Arrange(new Rect(0, 0, finalSize.Width * 2, finalSize.Height)); return finalSize; }); #endif }
public void handleRecipeInfo (TextView recipeInfo, LinearLayout.LayoutParams rill, JsonValue recipeResult) { recipeInfo.Text = handleRecipeJson (recipeResult); recipeInfo.SetTextAppearance (this, Android.Resource.Style.TextAppearanceSmall); recipeInfo.SetLines (1); recipeInfo.SetPadding (10, 0, 0, 0); }
/// <summary> /// Creates the meal info area in the programmitcally generated by Json. /// </summary> /// <returns>The meal info container for orginal Json calls.</returns> /// <param name="json">Json from original call to be parsed.</param> /// <param name="recipeResult">Recipe result (Json) using info from original Json.</param> /// <param name="count">Count used for creating unique ids.</param> private LinearLayout CreateMealInfo (JsonValue json, JsonValue recipeResult, int count) { LinearLayout mealInfo = new LinearLayout (this); mealInfo.Orientation = Orientation.Horizontal; mealInfo.SetMinimumWidth (25); mealInfo.SetMinimumHeight (25); LinearLayout.LayoutParams mealInfoLL = new LinearLayout.LayoutParams (LinearLayout.LayoutParams.MatchParent, LinearLayout.LayoutParams.WrapContent); mealInfoLL.SetMargins (5, 5, 5, 5); mealInfo.LayoutParameters = mealInfoLL; mealInfo.Id = count * 20 + 7; // Set image icon ImageView dinerIcon = new ImageView (this); dinerIcon.SetImageResource (Resource.Drawable.gray_person); dinerIcon.LayoutParameters = new LinearLayout.LayoutParams (50, LinearLayout.LayoutParams.MatchParent); // Finish setting the image icon TextView mealSize = new TextView (this); TextView recipeInfo = new TextView (this); recipeInfo.Text = handleRecipeJson (recipeResult); recipeInfo.SetTextAppearance (this, Android.Resource.Style.TextAppearanceSmall); recipeInfo.SetLines (1); LinearLayout.LayoutParams rill = new LinearLayout.LayoutParams (LinearLayout.LayoutParams.WrapContent, LinearLayout.LayoutParams.WrapContent); recipeInfo.LayoutParameters = rill; mealSize.SetTextAppearance (this, Android.Resource.Style.TextAppearanceSmall); LinearLayout.LayoutParams tvll = new LinearLayout.LayoutParams (LinearLayout.LayoutParams.WrapContent, LinearLayout.LayoutParams.WrapContent); mealSize.LayoutParameters = tvll; mealSize.Text = json ["Mealsize"].ToString (); recipeInfo.SetPadding (10, 0, 0, 0); mealSize.Gravity = GravityFlags.Right; // Add image icon mealInfo.AddView (mealSize); mealInfo.AddView (dinerIcon); mealInfo.AddView (recipeInfo); return mealInfo; }