xamarin forms mobile apps development Lab adjust the example code to complete th
ID: 3806929 • Letter: X
Question
xamarin forms mobile apps development
Lab adjust the example code to complete the assignment. The adjustments needed should mostly be content (the actual paragraph) and changes in the mathematical calculations. There should be very little actual program code changes needed. For ONE and only one PHONE Emulator (yes, it has to be a phone emulator): Use the Mathematical techniques to properly space and size the follow paragraph to display in the screen of the phone. public class EstimatedFontSizePage : ContentPage { Label label; public EstimatedFontSizePage() { label = new Label(); Padding = new Thickness(0, Device.OnPlatform(20, 0, 0), 0, 0); ContentView contentView = new ContentView { Content = label }; contentView.SizeChanged += OnContentViewSizeChanged; Content = contentView; } void OnContentViewSizeChanged(object sender, EventArgs args) { string text = "A default system font with a font size of S " + "has a line height of about ({0:F1} * S) and an " + "average character width of about ({1:F1} * S). " + "On this page, which has a width of {2:F0} and a " + "height of {3:F0}, a font size of ?1 should " + "comfortably render the ??2 characters in this " + "paragraph with ?3 lines and about ?4 characters " + "per line. Does it work?"; // Get View whose size is changing. View view = (View)sender; // Define two values as multiples of font size. double lineHeight = Device.OnPlatform(1.2, 1.2, 1.3); double charWidth = 0.5; // Format the text and get its character length. text = String.Format(text, lineHeight, charWidth, view.Width, view.Height); int charCount = text.Length; // Because: // lineCount = view.Height / (lineHeight * fontSize) // charsPerLine = view.Width / (charWidth * fontSize) // charCount = lineCount * charsPerLine // Hence, solving for fontSize: int fontSize = (int)Math.Sqrt(view.Width * view.Height / (charCount * lineHeight * charWidth)); // Now these values can be calculated. int lineCount = (int)(view.Height / (lineHeight * fontSize)); int charsPerLine = (int)(view.Width / (charWidth * fontSize)); // Replace the placeholders with the values. text = text.Replace("?1", fontSize.ToString()); text = text.Replace("??2", charCount.ToString()); text = text.Replace("?3", lineCount.ToString()); text = text.Replace("?4", charsPerLine.ToString()); // Set the Label properties. label.Text = text; label.FontSize = fontSize; } } please run the changed code and show screenshots
Explanation / Answer
//Uses aXml template and display items // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); // Get our button from the layout resource, // and attach an event to it Button button = FindViewById(Resource.Id.MyButton); TextView aLabel2 = FindViewById (Resource.Id.helloLabel); button.Click += delegate { button.Text = string.Format("{0} user clicks!", count++); aLabel2.Text = "Hello NHDN! " + count.ToString(); }; //Create the user interface in code var layout = new LinearLayout(this); layout.Orientation = Orientation.Vertical; var aLabel = new TextView(this); //aLabel.Text = "Hello, NHDN for Android"; // Set label as Fix text or from resource file aLabel.SetText(Resource.String.helloLabelText); var aButton = new Button(this); aButton.SetText(Resource.String.helloButtonText); ////Lambda way to delegate event //aButton.Click += (sender, e) => //{ // aLabel.Text = "Hello from the button"; //}; aButton.Click += delegate(object sender, EventArgs e) { aLabel.Text = string.Format("You clicked me {0} times "+ DateTime.Now.ToString() , count++); }; var aButton1 = new Button(this); //aButton.Text = "Say Hello"; aButton1.Text="Start Second Activity"; aButton1.Click += delegate(object sender, EventArgs e) { aButton1.Text = string.Format("clicked {0} " + DateTime.Now.ToString(), count++); // StartActivity(typeof(SecondActivity)); // start activity as intent and pass data between activities var second = new Intent(this, typeof(SecondActivity)); second.PutExtra("ActivityData", "Data from FirstActivity: " + aLabel.Text); StartActivity(second); }; layout.AddView(aLabel); layout.AddView(aButton); layout.AddView(aButton1); SetContentView(layout); var second = new Intent(this, typeof(SecondActivity)); second.PutExtra("ActivityData", "Data from FirstActivity: " + aLabel.Text); StartActivity(second); //Get data from FirstActivity var label = FindViewById (Resource.Id.screen2Label); label.Text = Intent.GetStringExtra("ActivityData") ?? "Data not available"; [Activity(Label = "Simple List of Books - Activity")] public class SimpleListActivity : ListActivity { protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.Main_list_view); // get list of books from xml file in your resource string[] books = Resources.GetStringArray(Resource.Array.books_array); ListAdapter = new ArrayAdapter(this, Resource.Layout.list_item, books); ListView.TextFilterEnabled = true; // add a listener to Item click ListView.ItemClick += delegate(object sender, ItemEventArgs args) { // When clicked, show a toast with the TextView text Toast.MakeText(Application," Selected Item: "+ ((TextView) args.View).Text,ToastLength.Short).Show(); }; } }Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.