Reputation: 4693
I would like to place two images in the respective image views so they occupy the entire screen. So far I have only gotten here :( (To add the device being tested I use an S3)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/white"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:onClick="onClick"
android:src="@drawable/up" />
<ImageView
android:id="@+id/blue"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:src="@drawable/blue"
android:onClick="onClick"
android:layout_below="@id/white"/>
</RelativeLayout>
The images are 1080 X 1920 and scaled to screen. The problem is either the image below is scaled improperly or they dont connect properly. I have a black area on the top and bottom
I am sorry but the Images are not of the same size.
Upvotes: 0
Views: 247
Reputation: 3273
You can achieve this by adding weightSum. Replace this xml
<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="match_parent"
tools:context=".MainActivity1" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:weightSum="1" >
<ImageView
android:id="@+id/white"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight=".5"
android:onClick="onClick"
android:src="@drawable/up" />
<ImageView
android:id="@+id/blue"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_below="@id/white"
android:layout_weight=".5"
android:onClick="onClick"
android:src="@drawable/blue" />
</LinearLayout>
</RelativeLayout>
it would look like as:
for more help.please add comments.
Upvotes: 2
Reputation: 22342
You should use a LinearLayout with layout_weight
set:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/white"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:onClick="onClick"
android:src="@drawable/up" />
<ImageView
android:id="@+id/blue"
android:layout_height="0dp"
android:layout_width="fill_parent"
android:layout_weight="1"
android:src="@drawable/blue"
android:onClick="onClick"
android:layout_below="@id/white"/>
</LinearLayout>
For the scaling issue, I'd recommend looking into scaleType
Upvotes: 0
Reputation: 11357
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:weightSum="2" >
<ImageView
android:id="@+id/white"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:onClick="onClick"
android:src="@drawable/up" />
<ImageView
android:id="@+id/blue"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:onClick="onClick"
android:src="@drawable/blue" />
</LinearLayout>
Upvotes: 1