2013-02-21 6 views
34

ラジオボタンを配置するには、私の相対layout..iはのEditText horizo​​ntally.Anyヘルプは高く評価され、それらを配置する苦労に直面しアンドロイド:以下、水平

<?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> 

Iamの上のラジオボタンを配置しようとしていますです。ただやる、他の上にラジオグループ(または他のビュー)を配置するために

+4

向きに従いますか? – njzk2

+0

どのように私はそれらの間に等しい間隔を与えますか – teekib

答えて

80

android:layout_above="@+id/view_below" 

だけで設定の向き変更するには:

android:orientation="horizontal" 

を、アイテムに等しい幅を与えるためには、を利用します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> 
+0

@ Sergio ..こんにちは..しかし、それは何もテキストを表示していません..テキストは黒.. – teekib

+0

私は答えを編集し、すべて一緒にコードを入れます。あなたと同じものかどうかを確認してください。 –

+0

@Sergio ... thnk you..perfect – teekib

4

相対レイアウトの代わりにテーブルレイアウトを使用できます。等間隔の場合

..テーブルの行の内部テーブルのレイアウトと場所ラジオボタンにに行を挿入し、以下の手順をラジオ・IN =「水平」

<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> 
+0

これは良いアイデアです。ユーザーは両方を選択でき、選択を解除できないためです。ラジオグループのユーザは、それらのうちの1つだけを選択することができ、新しいラジオボタンを選択することによって、選択されたラジオボタンは選択解除される。 – amin

関連する問題