user3209380
user3209380

Reputation: 169

How to show image in ImageView ?

I want show a picture in ImageView. I have an ImageView with width=200dip and height=200dip and I want show large image in imageView. I want center of image set in ImageView and another parts not shows but when I scroll image, I see up or down image. I know, I should reduce size of image(reduce width and height) because I cant use height memory and when size of image is large, android cant shows image. Now, How can I reduce width and height of image until can use this and not show memory low? How can I set image in center of ImageView and scroll this for see up and down of image?

Upvotes: 1

Views: 282

Answers (3)

Jayesh Prajapati
Jayesh Prajapati

Reputation: 19

    //Using xml

     <ImageView
        android:id="@+id/iv"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="centerCrop"
        android:src="@drawable/temp"
      />


  // By Codding

    ImageView iv = findViewById(R.id.iv);
    iv.setImageResource(R.drawable.temp);

Upvotes: 0

Sush
Sush

Reputation: 3874

I suggest better you use webview, with only one image tag and the path will be set dynamically, set the webview height and width according to your size and put larger image. so your image will scroll.

Upvotes: 0

Kirk
Kirk

Reputation: 5077

Here is the very simple example to show image,

Download Sample App

1st thing you can do it by XML Layout

<ImageView
    android:id="@+id/imageViewId"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:maxHeight="80dip" <!-- Set your image size, remember: px and dip is different -->
    android:maxWidth="80dip" <!-- Set your image size -->
    android:src="@drawable/your_image"
    android:gravity="center" />

if it is from file, and by programming !

ImageView imgView = (ImageView) findViewById(R.id.imageViewId);
imgView.setImageBitmap(BitmapFactory.decodeFile("pathToImageFile"));

if it is from drawables

ImageView imgView = (ImageView) findViewById(R.id.imageViewId);
imgView.setImageResource(R.drawable.imageFileId);

Upvotes: 2

Related Questions