Karnkuret
Karnkuret

Reputation: 33

Layout pushing views down the screen

So, I have a ImageView inside a FrameLayout. I need it this way. I feel like the issue here is the image and it's size itself. The layout the image is pushes further down all the other views on my screen leaving considerable empty space that's supposed to be from the layout.

I found that hard coding the height value let's me minimize this issue. If the height was wrap_content the image would reach up to the same point but the blank space that is supposed to be from the layout extends to extreme lengths.

So I want to know if this is a image size (or resolution?) problem (which seems to be) or anything else, and if there is a better solution than hardcoding the layout height. Thanks in advance.

Here is the code:

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

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="700dp">

        <ImageView
            android:id="@+id/image_header"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:scaleType="fitStart"
            android:src="@drawable/me_and_gundam" />

        <View
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/gradient" />
    </FrameLayout>


    <TextView
        android:fitsSystemWindows="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="16dp"
        android:text="My Nanodegree Apps!"
        android:textAlignment="center"
        android:textSize="24sp" />

And here is what it looks like:

enter image description here

Upvotes: 1

Views: 193

Answers (1)

kavya
kavya

Reputation: 21

have you tried putting frame layout height as wrap_content it worked for me fine

    <ImageView
        android:id="@+id/image_header"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scaleType="fitStart"
        android:src="@drawable/me_and_gundam" />

    <View
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/gradient" />
</FrameLayout>

Upvotes: 2

Related Questions