2013-04-27 2 views
1

У меня есть TableLayout с 2 столбцами: метка и поле ввода (Spinner, EditText, RadioGroup). Я хочу выровнять метку для RadioGroup точно в вертикальном выравнивании с текстом первого переключателя. Текст «Возьми его» должен быть на красной линии. Как это сделать? Является ли это возможным?Совместите метку с текстом первого RadioButton

example with label -> gravity=top

Вот XML - урезанная к соответствующему TableRow:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/layoutEditMedication1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    android:padding="16dp" 
    tools:context=".Main" > 

    <ScrollView 
    android:id="@+id/scrollView1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_above="@id/buttons" > 

    <TableLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:shrinkColumns="1" 
     android:stretchColumns="1" > 

     <TableRow style="@style/EditMedicationTableRowT" > 

     <TextView 
      style="@style/EditMedicationLabel" 
      android:layout_gravity="top" 
      android:text="@string/i_need_to_take" /> 

     <RadioGroup 
      style="@style/EditMedicationTableRowB" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" > 

      <RadioButton 
      android:id="@+id/radioScheduleDaily" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/schedule_daily" /> 

      <RadioButton 
      android:id="@+id/radioScheduleSpecial" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/schedule_special" /> 
     </RadioGroup> 
     </TableRow> 
    </TableLayout> 
    </ScrollView> 

</RelativeLayout> 

и используемые стили:

<resources> 
    <style name="EditMedicationTableRowT"> 
     <item name="android:paddingTop">8dp</item> 
     <item name="android:layout_width">fill_parent</item> 
     <item name="android:layout_height">wrap_content</item> 
    </style> 

    <style name="EditMedicationTableRowB"> 
     <item name="android:layout_width">fill_parent</item> 
     <item name="android:layout_height">wrap_content</item> 
     <item name="android:paddingBottom">8dp</item> 
     </style> 

    <style name="EditMedicationLabel"> 
     <item name="android:layout_width">wrap_content</item> 
     <item name="android:layout_height">wrap_content</item> 
     <item name="android:layout_gravity">center_vertical</item> 
     <item name="android:paddingRight">16dp</item> 
     <item name="android:textAppearance">?android:attr/textAppearanceMedium</item> 
    </style> 
</resources> 

Я знаю, что я мог бы сделать два TableRows с два разных RadioGroups каждый с одним RadioButton, а затем программно код что-то при этом они выглядят так, как будто они где-то RadioGroup. Но, возможно, есть простое решение.

API - 8 и выше.

+0

вы могли бы опубликовать XML вашего компоновщика? – zbr

+0

сделано ................ – koem

ответ

0

попробовать это

<TextView 
    style="@style/EditMedicationLabel" 
    android:layout_gravity="top" 
    android:paddingBottom="0dp" 
    android:text="@string/i_need_to_take" /> 
+0

извините, не посмотрели ваш ответ. Тем временем я делал это с строками дерева таблицы и группировал их по коду (последний абзац в OP) - thx в любом случае – koem

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