basti12354
basti12354

Reputation: 2520

Scale two imageViews in a relative layout, which are next to each other

I created my main.xml for normal screens. Everything is looking fine. Now I try to scale the imageViews to use larger screens. It was no problem to scale the imageView on the top and on the bottom, but there are two imageViews between them, which are next to each other.

main.xml:

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

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:src="@drawable/bergsteiger2"
            android:layout_alignParentTop="true"
            android:adjustViewBounds="true"
            android:layout_above="@+id/start" />

         <ImageButton
            android:id="@+id/start"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"

            android:layout_above="@+id/uebungen"
            android:background="?android:selectableItemBackground"

            android:src="@drawable/start"
            />

    <ImageButton
            android:id="@+id/anleitung"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@+id/uebungen"
            android:layout_above="@+id/impressum"
            android:background="?android:selectableItemBackground"

            android:src="@drawable/anleitung"
            />
    <ImageButton
            android:id="@+id/uebungen"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"


            android:background="?android:selectableItemBackground"
            android:layout_above="@+id/impressum"
            android:src="@drawable/uebungen"
            />



         <ImageButton
            android:id="@+id/impressum"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"


            android:background="?android:selectableItemBackground"
            android:layout_alignParentBottom="true"
                    android:layout_centerHorizontal="true"
            android:src="@drawable/impressum"
            />

    </RelativeLayout>

large\main.xml

<?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"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_above="@+id/start"
        android:layout_alignParentTop="true"
        android:adjustViewBounds="true"
        android:src="@drawable/bergsteiger2" />

    <RelativeLayout
        android:id="@+id/relativeLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/impressum"
        android:orientation="horizontal"


        android:layout_centerHorizontal="true"
        android:adjustViewBounds="true" >

        <ImageButton
            android:id="@+id/anleitung"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@+id/uebungen"
            android:background="?android:selectableItemBackground"
            android:src="@drawable/anleitung" />

        <ImageButton
            android:id="@+id/uebungen"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"

            android:adjustViewBounds="true"
            android:background="?android:selectableItemBackground"
            android:scaleType="fitXY"
            android:src="@drawable/uebungen" />
    </RelativeLayout>

    <ImageButton
        android:id="@+id/impressum"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:adjustViewBounds="true"
        android:background="?android:selectableItemBackground"
        android:scaleType="fitXY"
        android:src="@drawable/impressum" />

    <ImageButton
        android:id="@+id/start"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/relativeLayout1"
        android:layout_alignParentLeft="true"
        android:adjustViewBounds="true"
        android:background="?android:selectableItemBackground"
        android:scaleType="fitXY"
        android:src="@drawable/start" />

</RelativeLayout>

enter image description here

Left one is the large one, I want to scale "Übungen" and "Anleitung"

Upvotes: 1

Views: 766

Answers (1)

JasJar
JasJar

Reputation: 332

Add both views into a LinearLayout, use the sumweight property. The linear layout wil have a width matching the parent, and a sumweight of 2. Both images inside will have a width of 0dp, and a weight of 1. You can preserve the margins and all the attrbitues you're using right now. This way:

<LinearLayout
        android:id="@+id/relativeLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/impressum"
        android:orientation="horizontal"
        android:layout_centerHorizontal="true"
        android:adjustViewBounds="true"
        android:weightSum="2">

        <ImageButton
            android:id="@+id/anleitung"
            android:layout_width="0dp"
            android:layout_weigth="1"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@+id/uebungen"
            android:background="?android:selectableItemBackground"
            android:src="@drawable/anleitung" />

        <ImageButton
            android:id="@+id/uebungen"
            android:layout_width="0dp"
            android:layout_weigth="1"
            android:layout_height="wrap_content"
            android:adjustViewBounds="true"
            android:background="?android:selectableItemBackground"
            android:scaleType="fitXY"
            android:src="@drawable/uebungen" />
    </LinearLayout>

Hope it helps.

Upvotes: 1

Related Questions