user596186
user596186

Reputation: 589

Android: Positioning images?

How would I position images in the following layout...

|----------------------|
|                      |
|                      |
|   I             I    |
|                      |
|                      |
|                      |
|                      |
|                      |
|   I             I    |
|                      |
|                      |
------------------------

Where each I = an imageview.

Upvotes: 0

Views: 464

Answers (3)

Mark Allison
Mark Allison

Reputation: 21909

Try this:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent">
    <ImageView android:layout_height="wrap_content" android:src="@drawable/icon"
        android:id="@+id/imageView1" android:layout_width="wrap_content"
        android:layout_alignParentLeft="true" android:layout_alignParentTop="true"></ImageView>
    <ImageView android:layout_height="wrap_content" android:src="@drawable/icon"
        android:id="@+id/imageView2" android:layout_width="wrap_content"
        android:layout_alignParentRight="true" android:layout_alignParentTop="true"></ImageView>
    <ImageView android:layout_height="wrap_content" android:src="@drawable/icon"
        android:id="@+id/imageView3" android:layout_width="wrap_content"
        android:layout_alignParentLeft="true" android:layout_alignParentBottom="true"></ImageView>
    <ImageView android:layout_height="wrap_content" android:src="@drawable/icon"
        android:id="@+id/imageView4" android:layout_width="wrap_content"
        android:layout_alignParentRight="true" android:layout_alignParentBottom="true"></ImageView>
</RelativeLayout>

if you want to pull the images in from the edges, just apply android:layout_margin* attributes to the individual ImageView controls.

Upvotes: 1

Ted Hopp
Ted Hopp

Reputation: 234795

You can use a TableLayout, a RelativeLayout or nested LinearLayouts. Are all the images the same size and do you want them to fill the screen?

Upvotes: 1

user485498
user485498

Reputation:

Set your main layout to horizontal. Add two new layouts, Layout1, Layout2 to your mainlayout. Set them both to veritcal layout. Add 2 imageviews to layout1 and 2 imageviews to layout2.

Upvotes: 1

Related Questions