Как разместить элементы в нижней части экрана?

Интерфейс, диалоги, темы, стили, меню
Ответить
Oleg_SS
Сообщения: 34
Зарегистрирован: 11 янв 2012, 10:59

Как разместить элементы в нижней части экрана?

Сообщение Oleg_SS » 13 янв 2012, 07:27

По умолчанию элементы размещаются в верхней левой части экрана. Как их опустить вниз.
Как им сказать bottom?

Аватара пользователя
RagnarR
Сообщения: 29
Зарегистрирован: 11 янв 2012, 11:02
Откуда: Belarus

Re: Как разместить элементы в нижней части экрана?

Сообщение RagnarR » 13 янв 2012, 08:59

Надо использовать RelativeLayout и у необходимого элемента установить параметр

Код: Выделить всё

android:layout_alignParentBottom="true"
--[+++++++<---->>-->+>+>+<<<<]
<.>++++[-<++++<++>>>->--<<]>>-.>--..>+.<<<.<<-.>>+>->>.+++[.<]<<++.

Oleg_SS
Сообщения: 34
Зарегистрирован: 11 янв 2012, 10:59

Re: Как разместить элементы в нижней части экрана?

Сообщение Oleg_SS » 13 янв 2012, 09:07

да, получилось
только у меня внизу должны быть две кнопки горизонтально, а они слились одна над другой :(
мне надо, что бы эти кнопки были внизу, горизонтально и делили всю горизонтать пополам
Последний раз редактировалось Oleg_SS 13 янв 2012, 09:09, всего редактировалось 1 раз.

Аватара пользователя
damager82
Администратор
Сообщения: 1383
Зарегистрирован: 07 янв 2012, 11:32
Контактная информация:

Re: Как разместить элементы в нижней части экрана?

Сообщение damager82 » 13 янв 2012, 09:08

А какой ViewGroup используете? В LinearLayout, я думаю, это не получится сделать.
Тут вам FrameLayout или RelativeLayout нужен.
Добро пожаловать на форум сайта StartAndroid
ИзображениеИзображение

Oleg_SS
Сообщения: 34
Зарегистрирован: 11 янв 2012, 10:59

Re: Как разместить элементы в нижней части экрана?

Сообщение Oleg_SS » 13 янв 2012, 09:11

Код: Выделить всё

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/LinearLayout01" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical"
    android:background="@drawable/background_rectangle_white"
    android:padding="1dp">

    <TextView 
        android:id="@+id/LabelText01" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:text="Номер телефона" 
        android:layout_weight="0"
        android:textColor="@color/app_label_textcolor"
        android:textSize="20sp">
    </TextView>

    <Spinner
        android:id="@+id/cb_SMS_Phone_Ini_Sound"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:drawSelectorOnTop="true"
        android:text="EditText02" >
    </Spinner>
        
    <TextView 
        android:id="@+id/LabelText02" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:text="Сообщение" 
        android:layout_weight="0"
        android:textColor="@color/app_label_textcolor"
        android:textSize="20sp">
    </TextView>

    <Spinner
        android:id="@+id/cb_SMS_Text_Ini_Sound"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:drawSelectorOnTop="true"
        android:text="EditText02" >
    </Spinner>
   <TextView 
        android:id="@+id/LabelText03" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Звук при отправке сообщения" 
        android:layout_weight="0"
        android:textColor="@color/app_label_textcolor"
        android:textSize="20sp">
    </TextView>
    <Spinner
        android:id="@+id/cb_SMS_Send_Ini_Sound"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:drawSelectorOnTop="true"
        android:text="EditText02" >
    </Spinner>
   <TextView 
        android:id="@+id/LabelText04" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Звук подтверждения отправки сообщения" 
        android:layout_weight="0"
        android:textColor="@color/app_label_textcolor"
        android:textSize="20sp">
    </TextView>
    <Spinner
        android:id="@+id/cb_SMS_Send_OK_Ini_Sound"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:drawSelectorOnTop="true"
        android:text="EditText02" >
    </Spinner>
   <TextView 
        android:id="@+id/LabelText05" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Звук при получении сообщения" 
        android:layout_weight="0"
        android:textColor="@color/app_label_textcolor"
        android:textSize="20sp">
    </TextView>
    <Spinner
        android:id="@+id/cb_SMS_Receive_Ini_Sound"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:drawSelectorOnTop="true"
        android:text="EditText02" >
    </Spinner>
       
   <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/LinearLayout02" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="horizontal"
    android:background="#00007F">
       
       <Button
           android:id="@+id/bt_Save_Ini"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:text="Сохранить"
           android:layout_alignParentBottom="true"
           android:layout_weight="2"  />

       <Button
           android:id="@+id/bt_Cancel_Ini"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_alignParentBottom="true"
           android:layout_alignRight="@+id/bt_Save_Ini"
           android:layout_weight="2"
           android:text="Отменить" />
       
   </RelativeLayout>
           
</LinearLayout>

Oleg_SS
Сообщения: 34
Зарегистрирован: 11 янв 2012, 10:59

Re: Как разместить элементы в нижней части экрана?

Сообщение Oleg_SS » 13 янв 2012, 09:19

Спасибо!
Вот так получилось:

Код: Выделить всё

   <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/LinearLayout02" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical"
    android:background="#00007F">
    
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/LinearLayout01" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"
    android:layout_alignParentBottom="true"
    android:padding="5dp">

       <Button
           android:id="@+id/bt_Cancel_Ini"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_weight="2"
           android:text="Отменить" />

       <Button
           android:id="@+id/bt_Save_Ini"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_weight="2"
           android:text="Сохранить" />

</LinearLayout>
       
   </RelativeLayout>

gagarina4
Сообщения: 2
Зарегистрирован: 01 фев 2012, 14:37

Re: Как разместить элементы в нижней части экрана?

Сообщение gagarina4 » 01 фев 2012, 14:50

Всем привет, хочу спросить, а в моем случае как поместить кнопку New в низ экрана !? СКРИН. Какой лейаут в какой нужно размещать и почему вообще bottom не применяется к кнопке, спасибо)

Аватара пользователя
damager82
Администратор
Сообщения: 1383
Зарегистрирован: 07 янв 2012, 11:32
Контактная информация:

Re: Как разместить элементы в нижней части экрана?

Сообщение damager82 » 01 фев 2012, 17:52

gagarina4 писал(а):в моем случае как поместить кнопку New в низ экрана !?
Какой лейаут в какой нужно размещать и почему вообще bottom не применяется к кнопке, спасибо)
bottom не работает в LinearLayout с вертикальной ориентацией.


Вставьте между newact и LinearLayout03 пустой FrameLayout, который займет пространство и сдвинет кнопку вниз:

Код: Выделить всё

    <FrameLayout
        android:id="@+id/frameLayout1"
        android:layout_width="match_parent"
        android:layout_height="match_parent" android:layout_weight="1">
    </FrameLayout>
Добро пожаловать на форум сайта StartAndroid
ИзображениеИзображение

gagarina4
Сообщения: 2
Зарегистрирован: 01 фев 2012, 14:37

Re: Как разместить элементы в нижней части экрана?

Сообщение gagarina4 » 03 фев 2012, 11:36

Спасибо большое

Ответить