xamarin android align textview horizontally to RadioGroup

304 views Asked by At

I need to align Horizontally a TextView to the RadioButton.

I have a TableRow. Inside of it, I have a TextView and a RadioButton Horizontally with three options. The text of the TextView appears align horizontally at the top of the row, but I need to center horizontally so, they appear in the same line.

My code 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" >
        <TableLayout
              android:id="@+id/tableLayout1"
               android:layout_width="fill_parent"
               android:layout_height="wrap_content">
          <TableRow
             android:gravity="center_horizontal"
              android:layout_width="match_parent"
              android:layout_height="wrap_content">
            <TextView
              android:layout_width="wrap_content" 
              android:layout_height="wrap_content"
               android:gravity="center_horizontal"
              android:textSize="11sp"
                  android:text="Falta 220 V" />
            <RadioGroup android:orientation="horizontal">

              <RadioButton android:id="@+id/rdAlarma"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                            android:textSize="11sp"
                      android:textStyle="bold"
                  android:text="SI" />
              <RadioButton android:id="@+id/rdCCTV"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                            android:textSize="11sp"
                      android:textStyle="bold"
                  android:text="NO" />
              <RadioButton android:id="@+id/rdIncedio"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                            android:textSize="11sp"
                      android:textStyle="bold"
                 android:text="NA" />
            </RadioGroup>
          </TableRow>
         
        </TableLayout>
       
      </LinearLayout>
</FrameLayout>

And it looks like this.

enter image description here

1

There are 1 answers

3
Demitrian On BEST ANSWER

I was able to reproduce the issue using your code and found the issue. You were trying to set the android_gravity attribute of your TextView to center_horizontal rather than center_vertical

Try this instead:

<TextView
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:gravity="center_vertical"
    android:textSize="11sp"
    android:text="Falta 220 V" />