Здравствуйте создал объект 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]
Заранее большое спасибо!
Расположение элементов
-
- Сообщения: 6
- Зарегистрирован: 16 июн 2015, 07:37
Расположение элементов
Не бывает глупых вопросов, есть глупые ответы.
Re: Расположение элементов
Для этого используется RelativeLayout
Re: Расположение элементов
В данном случае можно не выходить за рамки 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 могут потребоваться дополнительные параметры, сейчас уже не вспомню какие.
[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 могут потребоваться дополнительные параметры, сейчас уже не вспомню какие.
-
- Сообщения: 6
- Зарегистрирован: 16 июн 2015, 07:37
Re: Расположение элементов
Я делаю типа прогресс бар, так как сам прогресс бар настроить как мне надо у меня пока не получилось.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]
Но добиться желаемого у меня пока не получилось...
Не бывает глупых вопросов, есть глупые ответы.