2014-07-21 113 views
0

雖然已選中this Q&A,但文本無法左對齊到Android中的RadioGroup。如何在Android中將文本左對齊到RadioGroup?

當前成果

enter image description here

預期結果

enter image description here

代碼

C:\工作空間ADT \的Helloworld \ RES \佈局\ activity_main.xml中

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context="com.example.helloworld.MainActivity" > 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:text="@string/fractions" /> 

    <RadioGroup 
     android:id="@+id/fractions" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" > 

     <RadioButton 
      android:id="@+id/fraction_true" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:checked="true" 
      android:paddingRight="15dip" 
      android:text="@string/fraction_true" /> 

     <RadioButton 
      android:id="@+id/fraction_false" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:paddingRight="15dip" 
      android:text="@string/fraction_false" /> 
    </RadioGroup> 

</RelativeLayout> 

C:\工作空間ADT \的Helloworld \ RES \值\的strings.xml

<?xml version="1.0" encoding="utf-8"?> 
<resources> 

    <string name="app_name">Helloworld</string> 
    <string name="fractions">Fractions</string> 
    <string name="action_settings">Settings</string> 
    <string name="fraction_true">True</string> 
    <string name="fraction_false">False</string> 

</resources> 

回答

2

好像一個水平線性佈局的情況。

<LinearLayout 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:gravity="center_vertical"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:text="lalalal" /> 

    <RadioGroup 
     android:id="@+id/fractions" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" > 

     <RadioButton 
      android:id="@+id/fraction_true" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:checked="true" 
      android:paddingRight="15dip" 
      android:text="lalalal" /> 

     <RadioButton 
      android:id="@+id/fraction_false" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:paddingRight="15dip" 
      android:text="lalalal" /> 
    </RadioGroup> 

</LinearLayout> 
1

使用Linear Layoutsweight。其中將使它簡單

檢查文檔

Layouts

或只用LinearLayout

<LinearLayout 
      android:id="@+id/linearLayout5" 
      android:layout_width= "fill_parent" 
      android:orientation="horizontal" 
      android:layout_gravity="center" 
      > 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:text="@string/fractions" /> 
      <RadioGroup 
       android:id="@+id/radioGroup1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:orientation="horizontal" > 

       <RadioButton 
     android:id="@+id/fraction_true" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:checked="true" 
     android:paddingRight="15dip" 
     android:gravity="center" 
     android:layout_gravity="center" 
     android:text="lalalal" /> 

    <RadioButton 
     android:id="@+id/fraction_false" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:paddingRight="15dip" 
     android:gravity="center" 
     android:layout_gravity="center" 
     android:text="lalalal" /> 

      </RadioGroup> 



     </LinearLayout> 
相關問題