2014-02-06 7 views
0

enter image description hereПочему разрыв выравнивания, когда я использовал селектор в android?

Привет, Я использую селектор в радио-кнопки, но мой макет break.can скажите, пожалуйста, как удалить, что bug.I использовать этот код.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <include layout="@layout/header" /> 

    <TableLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:paddingTop="20dp" 
     android:stretchColumns="2" > 

     <TableRow 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="#FFFF00" > 

      <TextView 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight=".5" 
       android:padding="5dp" 
       android:text="Eligibility confirmed:" /> 

      <RadioGroup 
       android:id="@+id/eligibility" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight=".5" 
       android:orientation="horizontal" > 

       <RadioButton 
        android:id="@+id/eligibilityYes" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:background="@drawable/redio_yes_selecetor" 
        android:checked="true" 
        android:text="yes" /> 

       <RadioButton 
        android:id="@+id/eligibilityNo" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:background="@drawable/radio_selector" 

        android:text="No" /> 
      </RadioGroup> 
     </TableRow> 

    </TableLayout> 

</LinearLayout> 

=====================

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 

    <item android:drawable="@android:color/transparent" android:state_checked="false"/> 
    <item android:drawable="@color/green" android:state_checked="true"/> 

![<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 

    <item android:drawable="@android:color/transparent" android:state_checked="false"/> 
    <item android:drawable="@color/red" android:state_checked="true"/> 

</selector>][2] 


    <?xml version="1.0" encoding="utf-8"?> 
    <RelativeLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/header" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:background="#AFA7EF" 
     android:gravity="center" 
     > 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_margin="10dp" 
      android:text="Obtaining Informed Consent Form" 
      android:textColor="#000000" 
      android:textSize="13sp" 
      /> 

    </RelativeLayout> 
+0

Попробуйте присвоить 'weight' для вашего' RadioButton' 'android: layout_weight =". 25 "' – GrIsHu

+0

Проверьте мой ответ на его работоспособность. – GrIsHu

+0

, пожалуйста, уточните мое обновление .. вопрос –

ответ

0

Назначают равное weight к обоим вашим RadioButton до android:layout_weight=".25", так как у вас есть вес 0.5 на ваш RadioGroup.

Попробуйте ниже кода

 <RadioGroup 
      android:id="@+id/eligibility" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight=".5" 
      android:orientation="horizontal" > 

      <RadioButton 
       android:id="@+id/eligibilityYes" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_weight=".25" 
       android:background="@drawable/redio_yes_selecetor" 
       android:button="@null" 
       android:checked="true" 
       android:drawableRight="@android:drawable/btn_radio" 
       android:padding="5dp" 
       android:text="yes" /> 

      <RadioButton 
       android:id="@+id/eligibilityNo" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_weight=".25" 
       android:background="@drawable/radio_selector" 
       android:button="@null" 
       android:drawableRight="@android:drawable/btn_radio" 
       android:padding="5dp" 
       android:text="No" /> 
     </RadioGroup> 

enter image description here

Если вы хотите установить текст на левой стороне, то вам необходимо сделать свойство кнопки для @null и вы должны установить drawable изображения RadioButton с правой стороны и текст с левой стороны.

Смежные вопросы