1

I try to use RelativeLayout to make an image over another, but needless empty space appears.

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

<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingLeft="12dp"
    android:paddingRight="12dp"
    android:paddingTop="12dp"
    android:gravity="top">

    <ImageView
        android:id="@+id/heroImage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/test3"
        android:layout_alignParentTop="true"
        android:scaleType="fitStart" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:src="@drawable/corner" />

</RelativeLayout>
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FFF"
    android:id="@+id/linearlayout_hero">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hero Appearance"/>
</LinearLayout>

You can see it between the image of Wolverine and text.

Onik
  • 19,396
  • 14
  • 68
  • 91
Sigmund
  • 748
  • 1
  • 8
  • 28
  • Can you define what you mean with "needless empty space"? You've provided 12dp of padding, and your image is a different aspect ratio than the frame in which it would reside. The only way you could fit the image in the space is to stretch it or clip the left and right sides. – Paul Lammertsma Sep 30 '15 at 23:10

4 Answers4

3

Add this to your ImageView

android:scaleType="fitStart"
android:adjustViewBounds="true"
Aakash
  • 5,181
  • 5
  • 20
  • 37
0

replace you bottom linear layout with this block

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:background="#FFF"
    android:id="@+id/linearlayout_hero">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hero Appearance"/>
</LinearLayout>
Ravi Gadipudi
  • 1,446
  • 1
  • 17
  • 30
0

You can put the LinearLayout inside the RelativeLayout like this:

    <LinearLayout
        android:id="@+id/linearlayout_hero"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/heroImage"
        android:background="#FFF">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hero Appearance" />
    </LinearLayout>
pgiitu
  • 1,671
  • 1
  • 15
  • 23
0

i'm trying to answer your question.

I think it's because your image(hero/corner) has a blank space at the bottom, because the width & height of the RelativeLayout is wrap content, so the RelativeLayout is fitted to the images.

Please check your image :)

Stevian
  • 143
  • 3
  • 10