Получить макет по желанию при изменении ориентации - PullRequest
0 голосов
/ 11 ноября 2011

У меня есть такой XML-файл.На вертикальной ориентации все выглядит идеально.Но когда ориентация меняется, я не получаю макет, как я хотел, означает, что вещи не выровнены. Как я могу сделать это правильно. Заранее спасибо

 <RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent" android:background="@drawable/bg"    
   android:orientation="vertical">

 <ImageView android:id="@+id/imageVi" android:layout_width="wrap_content" 
   android:src="@drawable/header" android:layout_height="wrap_content">
    </ImageView>
 <TableLayout android:id="@+id/tableLayout2" android:layout_width="match_parent" android:layout_height="match_parent">
         <TableRow android:id="@+id/tableRowe"  android:layout_width="wrap_content" android:layout_height="50dip">
           </TableRow>
  <TableRow android:id="@+id/tableRowe"  android:layout_width="wrap_content" android:layout_height="550dip">
           </TableRow>
          <TableRow android:id="@+id/tableRow4"  android:layout_width="wrap_content" android:layout_height="wrap_content">
               <Button  android:layout_width="80dip" android:layout_marginLeft="20dip"  android:layout_marginTop="120dip" android:layout_height="80dip" android:background="@drawable/sched" android:id="@+id/sched"></Button>

        <Button  android:layout_width="80dip" android:layout_marginLeft="20dip"  android:layout_marginTop="120dip" android:layout_height="80dip" android:background="@drawable/viewsched" android:id="@+id/viewsched"></Button>
               <Button   android:layout_width="80dip" android:layout_marginLeft="20dip"  android:layout_marginTop="120dip" android:layout_height="80dip" android:background="@drawable/template" android:id="@+id/template"></Button>
       </TableRow>

          <TableRow android:id="@+id/tableRow5" android:layout_width="5dip" android:layout_height="wrap_content">
            <TextView android:text="Add new" android:minLines="3" android:textColor="@color/black" android:gravity="center" android:layout_width="20dip" android:layout_height="50dip" android:id="@+id/text_coutdet_city"></TextView>
          <TextView android:text="View Scheduler" android:minLines="3" android:textColor="@color/black" android:gravity="center" android:layout_width="20dip" android:layout_height="50dip" android:id="@+id/text_coutdet_city"></TextView>
          <TextView android:text="Message Templates" android:minLines="3" android:textColor="@color/black" android:gravity="center" android:layout_width="20dip" android:layout_height="50dip" android:id="@+id/text_coutdet_city"></TextView>

          </TableRow>


           <TableRow android:id="@+id/tableRow6" android:layout_width="wrap_content" android:layout_height="wrap_content">
           <Button  android:layout_width="80dip" android:layout_marginLeft="20dip"  android:layout_marginTop="10dip" android:layout_height="80dip"  android:background="@drawable/upcmng" android:id="@+id/upcmng"></Button>
        <Button   android:layout_width="80dip" android:layout_marginLeft="20dip"  android:layout_marginTop="10dip" android:layout_height="80dip"  android:background="@drawable/log" android:id="@+id/log"></Button>
               <Button   android:layout_width="80dip" android:layout_marginLeft="20dip"  android:layout_marginTop="10dip" android:layout_height="80dip"  android:background="@drawable/help" android:id="@+id/help"></Button>
         </TableRow>

        <TableRow android:id="@+id/tableRow7" android:layout_width="wrap_content" android:layout_height="wrap_content">
              <TextView android:text="Upcoming birthdays" android:minLines="3" android:textColor="@color/black" android:gravity="center" android:layout_width="20dip" android:layout_height="50dip" android:id="@+id/text_coutdet_city"></TextView>
       <TextView android:text="Birthday Log" android:minLines="3" android:textColor="@color/black" android:gravity="center" android:layout_width="20dip" android:layout_height="50dip" android:id="@+id/text_coutdet_city"></TextView>
       <TextView android:text="Help" android:minLines="3" android:textColor="@color/black" android:gravity="center" android:layout_width="20dip" android:layout_height="50dip" android:id="@+id/text_coutdet_city"></TextView>
       </TableRow>

      </TableLayout>

Ответы [ 3 ]

1 голос
/ 11 ноября 2011

Два способа сделать это.

  1. Создание отдельного макета, как описано в документации

Макет ландшафта Если вы хотите другой дизайн для ландшафта, поставьте XML-файл вашего макета внутри / res / layout-land. Android будет автоматически смотрите здесь, когда меняется макет. Без этого особенного Определен альбомный макет, Android растянет макет по умолчанию.

  1. Настройка параметров ширины и высоты соответствующим образом.
1 голос
/ 11 ноября 2011

Создайте новый XML-файл с именем, точно таким же, как ваш XML-файл, и поместите его в папку с именем layout-land. Это XML-файл, который Android будет использовать для вашей активности в режиме Ladscape. Теперь просто измените его в соответствии с вашими представлениями о ландшафте.

0 голосов
/ 11 ноября 2011

Вы должны указать параметры RelativeLayout, например:

<ImageView android:id="@+id/imageVi"
    ...
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    ... >
</ImageView>

<TableLayout
    ...
    android:layout_alignTop="@id/imageVi"
    android:layout_alignParentLeft="true"
    ... >

        ...
</TableLayout>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...