0

I'm using the Rotten Tomatoes sample app from here: Rotten Tomatoes sample app.

But the movie poster images are not displaying full size on my phone. The layout width and height properties are both set to "wrap_content", but the images display shrunken. I have to set an actual pixel size for the width and height in order for them to display properly. I don't know why this is happening.

Does not work:

<ImageView
    android:id="@+id/ivPosterImage"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:src="@drawable/large_movie_poster" />

Does work:

<ImageView
    android:id="@+id/ivPosterImage"
    android:layout_width="121dp"
    android:layout_height="179dp"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:src="@drawable/large_movie_poster" />
MrLore
  • 3,759
  • 2
  • 28
  • 36
Mike
  • 632
  • 2
  • 7
  • 17
  • I assume that you download each image. Are you setting the images to the imageview after you downloaded them? – ezcoding Feb 21 '14 at 21:17
  • I think that the imageview has the size of your drawable source and when you apply a new image to it, the size of your imageview won't change, since it's size has already been calculated – ezcoding Feb 21 '14 at 21:45
  • When it loads the movie it is setting the size in code, which apparently has no effect. `Picasso.with(this).load(movie.getLargePosterUrl()). resize(120, 177).placeholder(R.drawable.large_movie_poster). into(ivPosterImage);` – Mike Feb 21 '14 at 21:55
  • The odd thing is that the original "dummy" image (drawable/large_movie_poster) loads full size right before being replaced with the downloaded image and then shrinks. – Mike Feb 21 '14 at 21:57
  • If the downloaded image has it's density set to the default density and the image for the resources folder has the device density, which is a different one (in our case 'high') then our freshly downloaded image would shrink. Maybe you have to create the downloaded as a bitmap like this Bitmap bitmap = BitmapFactory.decodeByteArray... And then you could set the density of the bitmap with the actual device density: bitmaps.setDensity(getResources().getDisplayMetrics().density); And finally imageView.setImageBitmap(bitmap); – ezcoding Feb 21 '14 at 22:24
  • Bit depth is the same (24), but the horizontal and vertical resolutions are different, 96dpi for the image in the resources folder and 72dpi for the downloaded image. – Mike Feb 22 '14 at 19:24

2 Answers2

0

You should take a look at What is the difference between "px", "dp", "dip" and "sp" on Android? to understand what the unit types mean and get your head around how android scales things.

You can then set the scaletype of your image view's to the various different options available and see what gives you the results you expect OR set the units to px (not recommended), bear in mind that if you use the images 'at their full size' in px the image will be scaled differently in relation to other elements on different screen sizes

Community
  • 1
  • 1
Nick Cardoso
  • 20,807
  • 14
  • 73
  • 124
  • Thanks. Yes, I do know there is a difference between the units. My point is that I have to specify some value in order to get the images to display the proper size intead of having the images automatically display the full size. I should not have to specify a size. – Mike Feb 21 '14 at 21:35
0

ImageView doesn't resize on its own.

Once you downloaded the image, get its height and width and set the ImageView's Layout Parameters to those sizes.

In case the image's width is greater than the phone screen, set the width of the ImageView to the screen width and scale the height accordingly.

dannyroa
  • 5,501
  • 6
  • 41
  • 59