Проблемы с разметкой

Ответить
Аватара пользователя
rezak90
Сообщения: 3422
Зарегистрирован: 26 июн 2012, 13:22
Откуда: UA
Контактная информация:

Проблемы с разметкой

Сообщение rezak90 » 11 сен 2012, 11:06

Реализовываю ActionBar. Но вот красивую разметку что то не поулчается. Проблема в том что в Eclipse выглядит так:

ИзображениеИзображение

а в эмуляторе уже выглядит вот так:

ИзображениеИзображение

Это первая проблема.
Вторая проблема это то что бы компоненты во втором и третьем контейнеры размещались по центру. Сейчас они размещены все слева:

ИзображениеИзображение

Кидаю саму разметку:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:baselineAligned="false"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#FFFFFF" >

<RelativeLayout
android:id="@+id/relativeHome"
android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:layout_margin="8dp"
android:background="#C8EBFF" >

<Button
android:id="@+id/btnHome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/home" />

</RelativeLayout>

<LinearLayout
android:id="@+id/linearImage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:layout_weight="1"
android:background="#C8EBFF" >

<Button
android:id="@+id/btnPicture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:background="@drawable/picture" />

<TextView
android:id="@+id/tvImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:textColor="#000000"
android:textSize="14dp"
android:text="Galery" />

</LinearLayout>

<LinearLayout
android:id="@+id/linearSearch"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:layout_weight="1"
android:background="#C8EBFF" >

<Button
android:id="@+id/btnSearch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:background="@drawable/search" />

<TextView
android:id="@+id/tvSearch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:textColor="#000000"
android:textSize="14dp"
android:text="Search" />

</LinearLayout>

</LinearLayout>
R.id.team
Политика на форуме запрещена

AndreyI
Сообщения: 372
Зарегистрирован: 14 май 2012, 16:18

Re: Проблемы с разметкой

Сообщение AndreyI » 11 сен 2012, 11:59

Тут нужно поиграться с контейнерами, к примеру кнопку с текстом объединенные в LinearLayout можно вложить во FrameLayout а там уже они отцентруются. Обычные LinearLayout размещают все компоненты слева направо и сверху вниз (в зависимости от ориентации).
А чтобы высота была одинаковая, то применяем для android:layout_height не "wrap_content", а "fill_parent" или "match_parent" (чем они отличаются, я так и не понял), пусть они выравниваются по контейнерам.

Будет полезнее самому с этим повозиться, чтобы вникнуть в логику верстки, чем использовать готовое решение. ;)

Аватара пользователя
rezak90
Сообщения: 3422
Зарегистрирован: 26 июн 2012, 13:22
Откуда: UA
Контактная информация:

Re: Проблемы с разметкой

Сообщение rezak90 » 11 сен 2012, 17:54

Спасибо! Попробовал FrameLayout и действительно помогло. Просто им никогда не пользовался. Привык обходится LinerLayout'ом и редко ReletiveLayout. Вот что получилось:

ИзображениеИзображение

А вот и код:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:baselineAligned="false"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#FFFFFF" >

<RelativeLayout
android:id="@+id/relativeHome"
android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:layout_margin="8dp"
android:background="#C8EBFF" >

<Button
android:id="@+id/btnHome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/home" />

</RelativeLayout>

<FrameLayout
android:id="@+id/linearImage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:layout_weight="1"
android:background="#C8EBFF" >

<Button
android:id="@+id/btnPicture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center_horizontal"
android:background="@drawable/picture" />

<TextView
android:id="@+id/tvImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:paddingLeft="24dp"
android:textColor="#000000"
android:textSize="14dp"
android:text="Galery" />

</FrameLayout>

<FrameLayout
android:id="@+id/linearSearch"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:layout_weight="1"
android:background="#C8EBFF" >

<Button
android:id="@+id/btnSearch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center_horizontal"
android:background="@drawable/search" />

<TextView
android:id="@+id/tvSearch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:paddingLeft="24dp"
android:textColor="#000000"
android:textSize="14dp"
android:text="Search" />

</FrameLayout>

</LinearLayout>
З.Ы. тему можно закрывать.
R.id.team
Политика на форуме запрещена

Аватара пользователя
knight
Сообщения: 44
Зарегистрирован: 21 сен 2012, 09:25

Re: Проблемы с разметкой

Сообщение knight » 25 сен 2012, 08:06

fill_parent и math_parent ничем не отличаются, это одно и тоже. fill_parent это более устаревшее значение, приминялось до 2.0 версии, дальше его переименовали в math, но дабы избежать казусов оставили поддержку fill

Ответить