如何水平对齐RadioButton和TextView?

时间:2016-01-08 12:06:54

标签: android-studio radio-button radio-group

See the image... If I don't Use the RelativeLayout the output is TextView is below RadioButton

如果我使用以下代码水平对齐radioButtonTextView,则radioButton不会被识别为RadioGroup的一部分,这会导致多个选择。

<RelativeLayout 
        android:id="@+id/relative_layout_1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
<RadioGroup
            android:id="@+id/radioGroup"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentStart="true"
            android:layout_below="@+id/textView3">

         <RelativeLayout  
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">
         <RadioButton
                    android:id="@+id/radioButton3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:checked="false"
                    android:drawableLeft="@drawable/laptop_for_gaming"
                    android:text="@string/gaming" />
           <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_toEndOf="@id/radioButton3"                       
                    android:text="@string/gaming_desp" />
            </RelativeLayout>
         <RelativeLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">
                <RadioButton
                    android:id="@+id/radioButton4"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:drawableLeft="@drawable/laptop_professional_use"                                                            
                    android:text="@string/business_use" />
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_toEndOf="@+id/radioButton4"                       
                    android:text="@string/business_use_desp" />
            </RelativeLayout>

        </RadioGroup>

    </RelativeLayout>

如果我不使用RelativeLayout,它们不会水平对齐,而是一个在另一个之下。

2 个答案:

答案 0 :(得分:0)

你可以使用android:orientation =&#34; horizo​​ntal&#34;在您的RadioGroup上

答案 1 :(得分:0)

您必须关闭RadioKuttons后添加</RadioGroup>的无线电组:

<RadioGroup
            android:id="@+id/radioGroup"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentStart="true"
            android:layout_below="@+id/textView3">


        <RelativeLayout  
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">


         <RadioButton
                    android:id="@+id/radioButton3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:checked="false"
                    android:drawableLeft="@drawable/laptop_for_gaming"
                    android:text="@string/gaming" />
           <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_toEndOf="@id/radioButton3"                       
                    android:text="@string/gaming_desp" />
            </RelativeLayout>
      <RelativeLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingLeft="15dp"
                android:paddingRight="15dp">

                <RadioButton
                    android:id="@+id/radioButton4"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:checked="false"
                    android:drawableLeft="@drawable/laptop_professional_use"                                                            
                    android:text="@string/business_use" />


                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_toEndOf="@+id/radioButton4"                       
                    android:text="@string/business_use_desp" />
            </RelativeLayout>
</RadioGroup>
相关问题