Xamarin Android Button on Right an Left with Margin

1.7k views Asked by At

I have a complex View, in that i need to set Buttons at the bottom of the page. I need two rows of bottons, with one on the left and two on the right.

The way I manage to solve this is like this:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  <LinearLayout
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:orientation="vertical" >
    <ScrollView
          android:layout_width="match_parent"
          android:layout_height="0dp"
          android:layout_weight="1"
          android:fillViewport="true">
      ...........
          
    </ScrollView>
    <LinearLayout
         android:id="@+id/linearLayout1"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:gravity="center|bottom"
         android:orientation="horizontal">
      <TableLayout
              android:stretchColumns="1"
              android:id="@+id/tableLayout1"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content">
        <TableRow
             android:gravity="center_horizontal"
            android:layout_height="wrap_content">
          <Button
               android:textSize="12sp"
               android:id="@+id/btAnterior"
               android:layout_width="wrap_content"
               android:layout_height="30sp"
               android:text="A"
               android:background="@drawable/black_buttonSmall"
               style="@style/button_text" />
          <Button
             android:layout_gravity="right"
              android:textSize="12sp"
              android:id="@+id/btnGuardar"
              android:layout_width="wrap_content"
              android:layout_height="30sp"
              android:text="G"
              android:background="@drawable/black_buttonSmall"
              style="@style/button_text" />
          <Button
              android:layout_gravity="right"
              android:textSize="12sp"
              android:id="@+id/btnCancelar"
              android:layout_width="wrap_content"
              android:layout_height="30sp"
              android:text="C"
              android:background="@drawable/black_buttonSmall"
              style="@style/button_text" />
        </TableRow>
        <TableRow
                android:gravity="center_horizontal"
                android:layout_height="wrap_content">
          <Button
               android:textSize="12sp"
               android:id="@+id/btVolver"
               android:layout_width="wrap_content"
               android:layout_height="30sp"
               android:text="V"
               android:background="@drawable/black_buttonSmall"
               style="@style/button_text" />

          <Button
             android:layout_gravity="right"
              android:textSize="12sp"
              android:id="@+id/btnMateriales"
              android:layout_width="wrap_content"
              android:layout_height="30sp"
              android:text="Materiales"
              android:background="@drawable/black_buttonSmall"
              style="@style/button_text" />
          <Button
            android:layout_gravity="right"
            android:textSize="12sp"
            android:id="@+id/btnUltima"
            android:layout_width="wrap_content"
            android:layout_height="30sp"
            android:text="U"
            android:background="@drawable/black_buttonSmall"
            style="@style/button_text" />
        </TableRow>
      </TableLayout>
    </LinearLayout>

  </LinearLayout>
</FrameLayout>

It look like this

enter image description here

What I need is to set leftMargin on Left and Right.

How can I do it?

1

There are 1 answers

0
Stefanija On BEST ANSWER

this would look like this

Actually why don't you try something like this:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

  <!--Your code...-->

  <RelativeLayout
    android:layout_width="match_parent"
    android:layout_marginRight="20dp"
    android:layout_marginLeft="20dp"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom" >
    <LinearLayout
         android:layout_width="wrap_content"
         android:orientation="vertical"
         android:layout_height="wrap_content"
         android:layout_alignParentLeft="true"  >
      <Button
          android:layout_width="wrap_content"
          android:text="A"
          android:layout_height="wrap_content"/>
      <Button
         android:layout_width="wrap_content"
         android:text="B"
         android:layout_height="wrap_content"/>
    </LinearLayout>

    <LinearLayout
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:orientation="vertical"
         android:id="@+id/linearContainerHelper"
         android:layout_alignParentRight="true"  >
      <Button
         android:layout_width="wrap_content"
         android:text="C"
         android:layout_height="wrap_content"/>
      <Button
         android:layout_width="wrap_content"
         android:text="D"
         android:layout_height="wrap_content"/>
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:orientation="vertical"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@+id/linearContainerHelper">
      <Button
         android:layout_width="wrap_content"
         android:text="E"
         android:layout_height="wrap_content"/>
      <Button
         android:layout_width="wrap_content"
         android:text="F"
         android:layout_height="wrap_content"/>
    </LinearLayout>
  </RelativeLayout>

</FrameLayout>

If your parent-root is a RelativeLayout try using android:layout_alignParentBottom="true"istead of android:layout_gravity="bottom"