abuybuy
abuybuy

Reputation: 819

Why is the ImageView not in full screen?

I am doing an Android project. Why is the ImageView id iv1 and iv2 not in fullscreen? I've placed my XML down here:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:id="@+id/layout1"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:paddingBottom="10px"
              android:paddingLeft="10px"
>
    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
    >
        <ImageView
            android:id="@+id/iv1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:visibility="invisible"
        />

        <ImageView
            android:id="@+id/iv2"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:visibility="invisible"
        />

           <ImageButton
            android:id="@+id/menu_btn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_toRightOf="@+id/BunyiIng"
            android:src="@drawable/menu_btn"
            android:background="@null"
        />

        <ImageView
            android:id="@+id/image_logo"
             android:src="@drawable/logo_vehicle"
               android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@null"
            android:layout_marginTop="5px"
        />

    </RelativeLayout>
</LinearLayout>

If I placed the ImageViews in LinearLayout, it blocked the RelativeLayout.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:id="@+id/layout1"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:paddingBottom="10px"
              android:paddingLeft="10px"
>
    <ImageView
            android:id="@+id/iv1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:visibility="invisible"
    />

    <ImageView
        android:id="@+id/iv2"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:visibility="invisible"
    />

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
    >

But if the Imageview is placed below the RelativeLayout, but inside LinearLayout, the ImageView is not showing an image.

    </RelativeLayout>

    <ImageView
            android:id="@+id/iv1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:visibility="invisible"
    />

    <ImageView
            android:id="@+id/iv2"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:visibility="invisible"
    />
</LinearLayout>

How do I solve it? I want the ImageView showing the image in fullscreen.

Upvotes: 6

Views: 12618

Answers (3)

RajaReddy PolamReddy
RajaReddy PolamReddy

Reputation: 22493

Use this property for image view:

android:scaleType="fitXY"

Upvotes: 3

Alex Styl
Alex Styl

Reputation: 4219

I see that both of your ImageViews' height and width are set to "fill_parent", so I'm guessing that you want both of them to scale to the whole screen. In case you want them just to sit there and not going to use them for anything later, add

android:background="@drawable/your_drawable_here"

to both your linear and relative layouts. It will add an image to the background of the layout, scale it to fit the whole layout, and save some resources if I'm not mistaken.

Upvotes: 0

android developer
android developer

Reputation: 116322

  1. You have padding for the linear layout.
  2. You don't have anything in the imageview to see its content, so you can't see its content.
  3. You've set the imageview to be invisible, so you can't see its content.
  4. If you don't care about aspect ratio, use android:adjustViewBounds="false" and android:scaleType="fitXY".

Upvotes: 23

Related Questions