0

Пожалуйста, посмотрите на следующий XMLНевозможно выровнять элементы пользовательского интерфейса правильно

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="#ffffff" > 

    <TextView 
     android:id="@+id/save_txt" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="22dp" 
     android:text="@string/save_to" /> 

    <LinearLayout 
     android:id="@+id/save_location_radio_layout" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:layout_toRightOf="@+id/save_txt" 
     android:layout_marginTop="22dp" 
     android:layout_marginLeft="5dp" 
     android:layout_alignBaseline="@+id/save_txt"> 

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


    <RadioButton 
     android:id="@+id/radio_sd" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:checked="true" 
     android:text="SD" /> 

    <RadioButton 
     android:id="@+id/radio_phone" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Phone" /> 
    </RadioGroup> 
    </LinearLayout> 





    <TextView 
     android:id="@+id/save_name_txt" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/save_txt" 
     android:layout_marginTop="50dp" 
     android:text="@string/save_name" /> 

    <EditText 
     android:id="@+id/save_name_edt" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/save_txt" 
     android:layout_toRightOf="@+id/save_name_txt" 
     android:layout_alignBaseline="@+id/save_name_txt" 
     android:layout_marginLeft="15dp" 
     android:paddingBottom="10dp" 
     android:ems="8" > 

     <requestFocus /> 
    </EditText> 

    <Button 
     android:id="@+id/save_voice_note_button" 
     style="?android:attr/buttonStyleSmall" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/save_txt" 
     android:layout_toRightOf="@+id/save_name_edt" 
     android:layout_alignBaseline="@+id/save_name_edt" 
     android:layout_marginLeft="5dp" 
     android:paddingBottom="10dp" 
     android:text="@string/save" /> 

</RelativeLayout> 

Это порождает следующие

enter image description here

Есть 2 проблемы.

  1. Как вы можете видеть, RadioButton s не выровнены справа от «Save To:» TextView
  2. Это на самом деле Dialog и когда я открываю окно, высота окна не достаточно , См. Изображение, оно отображает только 90% от EditText и Button.

Я приложил все усилия, чтобы исправить это, но все равно ничего хорошего. Что я сделал не так?

+0

в вашей линейной компоновки удалить эти строки андроида: layout_marginTop = "22dp" андроид: layout_marginLeft = "5 диоптрий" андроид: layout_alignBaseline = «@ + id/save_txt» – rajeshwaran

ответ

1

Чтобы устранить проблему с высотой диалога, измените android:layout_height вашего основного RelativeLayout на wrap_content.

Для выравнивания радиокнопки с TextView, изменить @+id/save_txt и @+id/save_location_radio_layout к:

<TextView 
    android:id="@+id/save_txt" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/save_to" 
    android:gravity="center_vertical" 
    android:layout_alignTop="@+id/save_location_radio_layout" 
    android:layout_alignBottom="@+id/save_location_radio_layout"/> 

<LinearLayout 
    android:id="@+id/save_location_radio_layout" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:layout_toRightOf="@+id/save_txt" 
    android:layout_marginTop="22dp" 
    android:layout_marginLeft="5dp"> 
+0

Это сработало. Благодаря! –

0

место вашего сохранения: Текст зрения также в первой линейной компоновки и дать отступы между TextView и группой радио ..

0
try this out 

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="#ffffff" > 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="22dp" 
     android:id="@+id/headertop" 
     android:orientation="horizontal" > 

     <TextView 
      android:id="@+id/save_txt" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:text="save_to" /> 

     <LinearLayout 
      android:id="@+id/save_location_radio_layout" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="5dp" 

      android:layout_toRightOf="@+id/save_txt" 
      android:orientation="vertical" > 

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

       <RadioButton 
        android:id="@+id/radio_sd" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:checked="true" 
        android:text="SD" /> 

       <RadioButton 
        android:id="@+id/radio_phone" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Phone" /> 
      </RadioGroup> 
     </LinearLayout> 
    </LinearLayout> 

    <TextView 
     android:id="@+id/save_name_txt" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/headertop" 
     android:layout_marginTop="50dp" 
     android:text="save_name" /> 

    <EditText 
     android:id="@+id/save_name_edt" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignBaseline="@+id/save_name_txt" 
     android:layout_below="@+id/headertop" 
     android:layout_marginLeft="15dp" 
     android:layout_toRightOf="@+id/save_name_txt" 
     android:ems="8" 
     android:paddingBottom="10dp" > 

     <requestFocus /> 
    </EditText> 

    <Button 
     android:id="@+id/save_voice_note_button" 
     style="?android:attr/buttonStyleSmall" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignBaseline="@+id/save_name_edt" 
     android:layout_below="@+id/headertop" 
     android:layout_marginLeft="5dp" 
     android:layout_toRightOf="@+id/save_name_edt" 
     android:paddingBottom="10dp" 
     android:text="save" /> 

</RelativeLayout> 
0

В дополнение к выше замечания.

Вы не можете быть уверены, что все элементы подходят в диалоговом окне, потому что размер зависит от размеров экрана. Вы должны оптимизировать интерфейс, чтобы хорошо поместиться на большинстве экранов и обернуть ScrollView вокруг RelativeLayout. Это будет новый корневой элемент.

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