Skip to content Skip to sidebar Skip to footer

Android - Resize Image In Gallery Based On Device Resolution

I have an Android app that pulls in images from the Web. However when I set: the gallery appears to be set to the minimum sup

Solution 1:

try

i.setAdjustViewBounds(true);

also, you shoudn't use hardcoded pixel values (in i.setLayoutParams(new Gallery.LayoutParams(400, 300));)

use

int width = (int) getResources().getDimension(R.dimen.image_width)
int height = (int) getResources().getDimension(R.dimen.image_height)
i.setLayoutParams(new Gallery.LayoutParams(width, height));

and in some xml file (under res/values)

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <dimen name="image_height">400dp</dimen>
  <dimen name="image_width">300dp</dimen>
</resources>

Post a Comment for "Android - Resize Image In Gallery Based On Device Resolution"