V
V
Vanes Ri_Lax2015-06-17 08:01:19
Android
Vanes Ri_Lax, 2015-06-17 08:01:19

How to stick two ImageViews to different screen edges?

Hello, I have 2 ImageViews, how can I make them stick 1 to the left edge of the screen, the other to the right? Do they have to be on the same line?
Here is my XML code:

<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>

Thank you very much in advance!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Artem Voronov, 2015-06-17
@newross

Change RelativeLayout Properties

android:layout_width="match_parent"
android:layout_height="wrap_content"

Then remove the LinearLayout and add the appropriate ImageView
and
android:layout_alignParentRight="true"

O
Oleg Gamega, 2015-06-17
@gadfi

if you use LinearLayout, then specify android:orientation="horizontal" and between them you can put View as a filler, but in general, judging by the names, you need a toolbar where you have both a kosher logo and a normal icon menu, especially since you can put anything in it

S
Sergey Krasnodemsky, 2015-06-17
@Prognosticator

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="0dp"
    android:paddingRight="0dp"
    android:paddingTop="0dp"
    tools:context=".MainActivity">
    
        <ImageView
            android:id="@+id/imageView"
            android:layout_width="100dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_marginLeft="10dp"
            android:contentDescription="@string/logo"
            android:src="@drawable/logo"
            android:layout_alignParentLeft="true" />

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

</RelativeLayout>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question