Mayur
Mayur

Reputation: 799

Image not occupying full ImageView in layout

I have created a gallery which has default images when , one of it is clicked and displayed in other activity, but my problem is it does not occupy the whole screen when the image is loaded.

Here's the xml-

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drag_activity_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".DragActivity" >

    <ImageView
        android:id="@+id/imageViewEdit"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:src="@drawable/i1" />

</RelativeLayout>

and the images is loaded to this imageview from activity, using the following code.

Intent intent = getIntent();
        int ImageId = intent.getIntExtra("drawableId", 0);

        imgView = (ImageView) findViewById(R.id.imageViewEdit);
        imgView.setImageResource(ImageId);

enter image description here

Is their a way where image occupies the whole image view. Experts please help me, am new to android. Thanks in advance.

Upvotes: 0

Views: 544

Answers (5)

Refer this link https://developer.android.com/reference/android/widget/ImageView.ScaleType.html

Add android:scaleType="FIT_XY" to your ImageView.

Upvotes: 0

user2776223
user2776223

Reputation:

use imageView.setBackground() property

Upvotes: 0

FD_
FD_

Reputation: 12919

Change the ScaleType of the ImageView. Add this to your ImageView tag:

android:scaleType = "fitCenter"

Upvotes: 0

darnmason
darnmason

Reputation: 2732

set the android:scaleType attribute on the ImageView, something like centerCrop should fill the screen

Upvotes: 0

Apoorv
Apoorv

Reputation: 13520

Change

imgView.setImageResource(ImageId);

to

imgView.setBackgroundResource(ImageId);

Upvotes: 1

Related Questions