2013-09-30 4 views
0

У меня возникли проблемы с позиционированием этих видов. Я хочу сделать, как показано ниже. У меня есть два переключателя (rb_) и текст редактирования (et_) рядом с первым радиоприемником и расширяемое представление списка (lv_) рядом со вторым.Относительное расположение макета не работает должным образом

enter image description here

Я попытался следующий код, но не смог достичь того, чего я хочу, то et_new_trip получил толкнул вниз еще одну линию, а не справа от rb_create_new, то lv_old_trip не показывать вообще. Любая идея почему? Благодарю.

<RelativeLayout android:id="@+id/rl_trip" 
       android:layout_height="wrap_content" 
       android:layout_width="match_parent" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentTop="true"> 

    <RadioGroup android:id="@+id/rg_trip_creation" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
    > 
     <RadioButton android:id="@+id/rb_create_new" 
        style="@style/WrapContentWidthHeight" 
        android:text="New trip"/> 
     <EditText android:id="@+id/et_new_trip" 
        android:layout_height="30dp" 
        android:layout_width="200dp" 
        android:layout_toEndOf="@+id/rb_create_new" 
        android:layout_alignBottom="@+id/rb_create_new" 
        android:text="New Trip name"/> 

     <RadioButton android:id="@+id/rb_old_trip" 
        android:layout_height="30dp" 
        android:layout_width="200dp" 
        android:text="Previous trip"/> 
     <ExpandableListView 
      android:id="@+id/lv_old_trip" 
      android:layout_height="30dp" 
      android:layout_width="200dp" 
      android:layout_alignBottom="@+id/rb_old_trip" 
      android:layout_toEndOf="@+id/rb_old_trip" 
      /> 

    </RadioGroup> 

</RelativeLayout> 
+0

не это было бы проще, так как вертикальная LinearLayout, содержащее горизонтальную LinearLayout для каждой строки? –

+0

Согласен, linearlayout проще –

ответ

0

Вы включили Relative Layout внутри Radio Group, что является основной проблемой. Вот почему он так себя ведет. Удалите группу радиостанций, и ваш макет будет очень хорошим.

Ниже ид макет

<RelativeLayout 
     android:id="@+id/rl_trip" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:layout_marginTop="30dp" > 

     <RadioButton 
      android:id="@+id/rb_create_new" 
      android:layout_width="100dp" 
      android:layout_height="wrap_content" 
      android:text="New trip" /> 

     <EditText 
      android:id="@+id/et_new_trip" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_toEndOf="@+id/rb_create_new" 
      android:layout_toRighttOf="@+id/rb_create_new" 
      android:text="New Trip name" /> 

     <RadioButton 
      android:id="@+id/rb_old_trip" 
      android:layout_width="150dp" 
      android:layout_height="30dp" 
      android:layout_below="@+id/rb_create_new" 
      android:text="Previous trip" /> 

     <ExpandableListView 
      android:id="@+id/lv_old_trip" 
      android:layout_width="200dp" 
      android:layout_height="30dp" 
      android:layout_alignBottom="@+id/rb_old_trip" 
      android:layout_toEndOf="@+id/rb_old_trip" /> 
    </RelativeLayout> 

Если вы хотите, чтобы они в Radio Button вы можете сделать, как это, но одна вещь, которая будет всегда заботиться о является: Сопоставьте Высота радиокнопок и соответствующего Просмотр в правых

<LinearLayout 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=".MainActivity" > 

    <LinearLayout 
     android:id="@+id/rl_trip" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" > 

     <RadioGroup 
      android:id="@+id/rg_trip_creation" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" > 

      <RadioButton 
       android:id="@+id/rb_create_new" 
       android:layout_width="wrap_content" 
       android:layout_height="40dp" 
       android:text="New trip" /> 

      <RadioButton 
       android:id="@+id/rb_old_trip" 
       android:layout_width="wrap_content" 
       android:layout_height="40dp" 
       android:text="Previous trip" /> 
     </RadioGroup> 

     <LinearLayout 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:orientation="vertical" > 

      <EditText 
       android:id="@+id/et_new_trip" 
       android:layout_width="wrap_content" 
       android:layout_height="40dp" 
       android:text="New Trip name" /> 

      <ExpandableListView 
       android:id="@+id/lv_old_trip" 
       android:layout_width="wrap_content" 
       android:layout_height="40dp" 
       android:layout_alignBottom="@+id/rb_old_trip" 
       android:layout_toEndOf="@+id/rb_old_trip" /> 
     </LinearLayout> 
    </LinearLayout> 

</LinearLayout> 
+0

Спасибо, но моя RadioGroup находится внутри Relativelayout, а не наоборот. –

+0

Причина Я хочу, чтобы RadioGroup позволяла выбирать только один параметр. –

+0

Позвольте мне что-то попробовать –

0
<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=".MainActivity" > 
    <RadioGroup 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" > 

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

      <RadioButton 
       android:id="@+id/radioButton1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentTop="true" 
       android:layout_marginTop="75dp" 
       android:text="RadioButton" /> 

      <RadioButton 
       android:id="@+id/radioButton2" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentLeft="true" 
       android:layout_below="@+id/radioButton1" 
       android:layout_marginTop="30dp" 
       android:text="RadioButton" /> 

      <EditText 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignTop="@id/radioButton1" 
       android:layout_toRightOf="@id/radioButton1" 
       android:hint="et_new" /> 

      <ExpandableListView 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_alignTop="@id/radioButton2" 
       android:layout_toRightOf="@id/radioButton2" > 

      </ExpandableListView> 
     </RelativeLayout> 
    </RadioGroup> 
</RelativeLayout> 
Смежные вопросы