0

I am making a simple app in android studio, which includes two images filling up half of the screen, one on each side. Almost like a split screen. I have used this link: Make image appear half of the screen but it only makes an image appear on half of the screen when i want an image on either half. I would want something like this.enter image description here

This is the code which i am using:

<LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="0.5">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="0.5"
            >

            <ImageView
                android:id="@+id/ImageView_swamp"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:adjustViewBounds="true"
                android:src="@drawable/img" />

        </RelativeLayout>

        <View
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="0.5"
            />

    </LinearLayout>

Does anyone know what to do?

1 Answers1

0

You don't really need all the extra views. For vertical split screen:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/ImageView_swamp1"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.5"
        android:adjustViewBounds="true"
        android:src="@drawable/img" />

    <ImageView
        android:id="@+id/ImageView_swamp2"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.5"
        android:adjustViewBounds="true"
        android:src="@drawable/img" />

</LinearLayout>

enter image description here

For horizontal/lanscape split screen:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/ImageView_swamp1"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="0.5"
        android:adjustViewBounds="true"
        android:src="@drawable/img" />

    <ImageView
        android:id="@+id/ImageView_swamp2"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="0.5"
        android:adjustViewBounds="true"
        android:src="@drawable/img" />

</LinearLayout>

enter image description here

sleepystar96
  • 721
  • 3
  • 12