Расположение элементов

Интерфейс, диалоги, темы, стили, меню
Ответить
vanesrilax
Сообщения: 6
Зарегистрирован: 16 июн 2015, 07:37

Расположение элементов

Сообщение vanesrilax » 16 июн 2015, 14:37

Здравствуйте создал объект LinearLayout него добавил 2 элемента, они находят на одной горизонтали, но как мне сделать так чтобы 1 прилипал к левому краю, а второй к правому?
Вот исходный код активити:
[syntax=xml]<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="wrap_content"
android:layout_height="match_parent" android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="0dp"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/ActionBarCompat"
android:layout_width="fill_parent"
android:layout_height="50dp">

<ImageView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:src="@drawable/logo"
android:layout_marginTop="5dp"
android:layout_marginLeft="10dp"
android:contentDescription="@string/logo" />

<Button
android:layout_width="32dp"
android:layout_height="32dp"
android:id="@+id/button"
android:background="@drawable/phone"
android:singleLine="false"
style="?android:attr/buttonStyleSmall"
android:clickable="true"
android:visibility="visible"
android:layout_marginTop="5dp"
android:layout_marginLeft="10dp" />
</LinearLayout>
</RelativeLayout>[/syntax]
Заранее большое спасибо!
Не бывает глупых вопросов, есть глупые ответы.

Dark67
Сообщения: 72
Зарегистрирован: 23 июл 2012, 23:11

Re: Расположение элементов

Сообщение Dark67 » 16 июн 2015, 15:06

Для этого используется RelativeLayout

Аватара пользователя
klblk
Сообщения: 1097
Зарегистрирован: 18 окт 2012, 11:17
Откуда: г. Красноярск

Re: Расположение элементов

Сообщение klblk » 16 июн 2015, 15:24

В данном случае можно не выходить за рамки RelativeLayout:
[syntax=xml]<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="wrap_content"
android:layout_height="match_parent" android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="0dp"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<ImageView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:src="@drawable/logo"
android:layout_marginTop="5dp"
android:layout_marginLeft="10dp"
android:contentDescription="@string/logo" />

<Button
android:layout_width="32dp"
android:layout_height="32dp"
android:id="@+id/button"
android:background="@drawable/phone"
android:singleLine="false"
style="?android:attr/buttonStyleSmall"
android:clickable="true"
android:visibility="visible"
android:layout_marginTop="5dp"
android:layout_marginLeft="10dp"
android:layout_alignParentRight="true"/>
</RelativeLayout>[/syntax]

ключевое тут android:layout_alignParentRight="true"
Если почему-то хочется использовать LL то нужно смотреть в сторону weight и gravity, но для ImageView могут потребоваться дополнительные параметры, сейчас уже не вспомню какие.

vanesrilax
Сообщения: 6
Зарегистрирован: 16 июн 2015, 07:37

Re: Расположение элементов

Сообщение vanesrilax » 17 июн 2015, 07:53

klblk писал(а):В данном случае можно не выходить за рамки RelativeLayout:
Я делаю типа прогресс бар, так как сам прогресс бар настроить как мне надо у меня пока не получилось.
Не много изменил структуру и у меня теперь XML выглядит вот так:
[syntax=xml]<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="wrap_content"
android:layout_height="match_parent" android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="0dp"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/ActionBarCompat"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:baselineAligned="false">

<ImageView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:src="@drawable/logo"
android:layout_marginLeft="10dp"
android:contentDescription="@string/logo"
android:layout_gravity="center_vertical" />

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView2"
android:src="@drawable/phone"
android:layout_gravity="center_vertical" />

</LinearLayout>
</RelativeLayout>

[/syntax]
Но добиться желаемого у меня пока не получилось...
Не бывает глупых вопросов, есть глупые ответы.

Ответить