broliverparker
broliverparker

Reputation: 217

Formatting Layouts on Xamarin with Visual Studio 2017

I am trying to create a page on my mobile app that shows a list of student accommodations. It is supposed to display the address and then have a button underneath that links to a page which displays more information. I have tried using LinearLayout and RelativeLayout (see as below) Linear

Relative

The code I am using to create this is

                    LinearLayout newLayout = new LinearLayout(Application.Context);
                TextView displayAddress = new TextView(Application.Context);
                displayAddress.Text = "Address: " + accomodation.address1 + ", " + accomodation.address2 + ", " +
                    accomodation.city + ", " + accomodation.postcode;
                newLayout.AddView(displayAddress);
                Button moreInformation = new Button(Application.Context);
                moreInformation.Text = "More Info";
                moreInformation.SetY(displayAddress.GetY() + 100);
                newLayout.AddView(moreInformation);
                mainLayout.AddView(newLayout);

Is there any way I can format either layout so the button sits nicely underneath the text? Thank you.

Upvotes: 1

Views: 150

Answers (1)

York Shen
York Shen

Reputation: 9084

You could create a .axml layout to implement this function, for example :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
  <TextView
      android:id="@+id/textView_displayAddress"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:text="Address:  accomodation.address1  accomodation.address2 accomodation.city  accomodation.postcode" />
  <Button
      android:id="@+id/moreInformation"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:text="moreInfo" />
</LinearLayout>

Effect.

Upvotes: 1

Related Questions