O'Reilly logo

Xamarin Mobile Development for Android Cookbook by Matthew Leibowitz

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating user interface layouts

All apps require some form of user interface for the user to input data or view the output of information.

How to do it...

Creating an interface for our apps is very easy. There are two ways to create user interfaces, with code or with XML:

  • If we are using code to create a button on the screen, we would do something similar to this:
    protected override void OnCreate(Bundle bundle)
    {
      base.OnCreate(bundle);
    
      LinearLayout layout = new LinearLayout(this);
      layout.Orientation = Orientation.Vertical;
    
      Button button = new Button(this);
      button.Text = "Hello World!";
      layout.AddView(
        button, 
        ViewGroup.LayoutParams.MatchParent,
        ViewGroup.LayoutParams.WrapContent);
    
      SetContentView(layout);
    }

Both XML and code can be used to create equivalent ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required