ti-enxame.com

Android: posicionando os botões de opção horizontalmente

Abaixo está o meu layout relativo ... Estou tentando colocar os botões de opção acima do edittext

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:Android="http://schemas.Android.com/apk/res/Android"
    Android:layout_width="match_parent"
    Android:layout_height="wrap_content"
    Android:background="#FFFFFF" >

    <ImageView
        Android:id="@+id/fbreplycancel"
        Android:layout_width="wrap_content"
        Android:layout_height="wrap_content"
        Android:layout_alignParentRight="true"
        Android:layout_alignParentTop="true"
        Android:src="@drawable/fbcancel" />

    <RelativeLayout
        Android:id="@+id/relativeLayout1"
        Android:layout_width="80dp"
        Android:layout_height="250dp"
        Android:layout_alignParentRight="true"
        Android:layout_below="@+id/fbcancel" >

        <Spinner
            Android:id="@+id/replyspinner"
            Android:layout_width="50dp"
            Android:layout_height="30dp"
            Android:layout_alignLeft="@+id/fbshare"
            Android:layout_alignRight="@+id/fbshare"
            Android:layout_below="@+id/fbshare"
            Android:layout_marginTop="16dp"
            Android:drawSelectorOnTop="true"
            Android:entries="@array/fbcommentlist"
            Android:visibility="gone" />

        <Button
            Android:id="@+id/fbshare"
            Android:layout_width="wrap_content"
            Android:layout_height="wrap_content"
            Android:layout_alignParentBottom="true"
            Android:layout_centerHorizontal="true"
            Android:background="@drawable/fbbuttons"
            Android:text="@string/share" />

        <ImageView
            Android:id="@+id/fbpeople"
            Android:layout_width="wrap_content"
            Android:layout_height="wrap_content"
            Android:layout_above="@+id/fbshare"
            Android:layout_centerHorizontal="true"
            Android:layout_marginBottom="19dp"
            Android:background="@drawable/people2"
            Android:drawSelectorOnTop="true"
            Android:paddingTop="20dp" />

        <RadioButton
            Android:id="@+id/radio2"
            Android:layout_width="wrap_content"
            Android:layout_height="wrap_content"
            Android:layout_alignParentLeft="true"
            Android:layout_centerVertical="true"
            Android:text="RadioButton" />
    </RelativeLayout>

    <View
        Android:layout_width="250dp"
        Android:layout_height="0.7dip"
        Android:layout_alignParentLeft="true"
        Android:layout_alignParentRight="true"
        Android:layout_below="@+id/imageView1"
        Android:background="#3b5998" />

    <ImageView
        Android:id="@+id/imageView1"
        Android:layout_width="wrap_content"
        Android:layout_height="wrap_content"
        Android:layout_alignBottom="@+id/fbcancel"
        Android:layout_alignParentLeft="true"
        Android:layout_alignParentTop="true"
        Android:paddingRight="2dp"
        Android:src="@drawable/askabud" />

    <TextView
        Android:id="@+id/fbcommentpostedby"
        Android:layout_width="wrap_content"
        Android:layout_height="wrap_content"
        Android:layout_alignLeft="@+id/fbedittext"
        Android:layout_alignRight="@+id/fbcommentdisplay"
        Android:layout_below="@+id/imageView1"
        Android:layout_marginTop="15dp"
        Android:textColor="#000000" />

    <TextView
        Android:id="@+id/fbcommentdisplay"
        Android:layout_width="wrap_content"
        Android:layout_height="wrap_content"
        Android:layout_alignLeft="@+id/fbedittext"
        Android:layout_below="@+id/fbcommentpostedby"
        Android:layout_toLeftOf="@+id/relativeLayout1"
        Android:textColor="#000000" />

    <TextView
        Android:id="@+id/fbtextview"
        Android:layout_width="wrap_content"
        Android:layout_height="wrap_content"
        Android:layout_alignBottom="@+id/imageView1"
        Android:layout_toLeftOf="@+id/fbreplycancel"
        Android:layout_toRightOf="@+id/imageView1"
         Android:text="@string/replyrecommend" 
          Android:textSize="18sp"
          Android:textColor="#000000"/>

    <TextView
        Android:id="@+id/fbplacename"
        Android:layout_width="wrap_content"
        Android:layout_height="wrap_content"
        Android:layout_alignLeft="@+id/fbcommentdisplay"
        Android:layout_alignRight="@+id/fbcommentdisplay"
        Android:layout_below="@+id/fbcommentdisplay"
        Android:textColor="#000000" />

    <EditText
        Android:id="@+id/fbedittext"
        Android:layout_width="wrap_content"
        Android:layout_height="wrap_content"
        Android:layout_alignParentLeft="true"
        Android:layout_below="@+id/fbplacename"
        Android:layout_marginLeft="19dp"
        Android:layout_marginTop="45dp"
        Android:layout_toLeftOf="@+id/relativeLayout1"
        Android:background="@drawable/roundcorners"
        Android:ems="10"
        Android:hint="@string/fbhint"
        Android:lines="6"
        Android:scrollHorizontally="true"
        Android:textSize="14sp"
        Android:windowSoftInputMode="stateHidden" />

    <RadioGroup
        Android:id="@+id/radioGroup1"
        Android:layout_width="wrap_content"
        Android:layout_height="wrap_content"
        Android:layout_alignParentLeft="true"
        Android:layout_below="@+id/fbplacename" >

        <RadioButton
            Android:id="@+id/radio0"
            Android:layout_width="30dp"
            Android:layout_height="30dp"
            Android:checked="true"
            Android:text="1"
             />
    </RadioGroup>

    <RadioGroup
        Android:id="@+id/radioGroup2"
        Android:layout_width="wrap_content"
        Android:layout_height="wrap_content"
        Android:layout_alignTop="@+id/radioGroup1"
        Android:layout_toLeftOf="@+id/relativeLayout1" >

        <RadioButton
            Android:id="@+id/radio0"
            Android:layout_width="26dp"
            Android:layout_height="wrap_content"
            Android:checked="true"
            Android:text="3" />

        <RadioButton
            Android:id="@+id/radio2"
            Android:layout_width="wrap_content"
            Android:layout_height="wrap_content"
            Android:text="RadioButton" />
    </RadioGroup>

    <RadioButton
        Android:id="@+id/radio1"
        Android:layout_width="30dp"
        Android:layout_height="30dp"
        Android:layout_alignTop="@+id/radioGroup2"
        Android:layout_toLeftOf="@+id/radioGroup2"
        Android:text="2" />

</RelativeLayout>

Estou enfrentando dificuldades para organizá-las horizontalmente. Qualquer ajuda é apreciada.

52
teekib

Para colocar um grupo de rádio (ou qualquer outra visualização) acima da outra, basta:

Android:layout_above="@+id/view_below"

Para alterar a orientação basta definir:

Android:orientation="horizontal"

E para dar largura igual aos itens, use layout_weight:

<RadioGroup
    Android:id="@+id/radio_group"
    Android:layout_width="match_parent"
    Android:layout_height="wrap_content"
    Android:orientation="horizontal"
    Android:layout_above="@+id/view_below" >

    <RadioButton
        Android:id="@+id/radio1"
        Android:layout_width="0dp"
        Android:layout_weight="1"
        Android:layout_height="wrap_content"
        Android:checked="true"
        Android:text="First" />

    <RadioButton
        Android:id="@+id/radio2"
        Android:layout_width="0dp"
        Android:layout_weight="1"
        Android:layout_height="wrap_content"
        Android:text="Second" />
</RadioGroup>
116
Sergio Carneiro

Você pode usar o layout da tabela em vez do layout relativo. Inserir linha no layout da tabela e colocar botões de opção dentro da linha da tabela.

Para espaçamento igual, siga o procedimento a seguir

<TableRow
        Android:id="@+id/tableRow2"
        Android:layout_width="0dp"
        Android:layout_height="wrap_content"
        Android:layout_marginTop="50dp" >

        <RadioButton
            Android:id="@+id/button2"
            Android:layout_width="5dp"
            Android:layout_height="60dp"
            Android:layout_weight="1"
            Android:text="@string/btnReject"
            Android:onClick="onCallRejectButton" />

        <RadioButton
            Android:id="@+id/button1"
            Android:layout_width="5dp"
            Android:layout_height="60dp"
            Android:layout_weight="1
            Android:onClick="onCallAcceptButton"
            Android:text="@string/btnAccept" />

    </TableRow>
6
Zain