-1

Good morning. I have an image that is large as all display width. I want that this image is resized for all screen dimension and density. I have put into directory drawable-ldpi,mdpi,hdpi and xhdpi the image in various dimension, but for same display, such as the Galaxy Note or the Galay Nexus, the image don't take all screen width ! Why ? How can I do ?

Thanks

MimmoG
  • 631
  • 3
  • 14
  • 25

4 Answers4

0

The easiest way not always the best, so I would consider other options. But if you create an image for the XHDPI devices and put it in the xhdpi folder. Devices that are lower then xhdpi will automaticly scale the image down for you.

take look here

hope this helps

Maikel Bollemeijer
  • 6,545
  • 5
  • 25
  • 48
-1

// use

android:scaleType="fitXY"

normal hdpi is 480x 800 ~240dpi

but your

samsung note is 800 x 1280 pixels, 5.3 inches (~285 ppi pixel density)
galaxy nexus is 720 x 1280 pixels, 4.65 inches (~316 ppi pixel density)

or get the screen density using Displaymetrics and supply various image for different density.

Padma Kumar
  • 19,893
  • 17
  • 73
  • 130
-2

you have to create an image in your manifest.XML. Then, for the property, you just have to put

android:layout_width="wrap_content"
android:layout_height="wrap_content"

To set the width and heignt of the picture. Here, it will show the image on the whole screen.

clement
  • 4,204
  • 10
  • 65
  • 133
  • if the picture is smaller than the screen, YES. Otherwise, you just have to crop it in the code as say in http://stackoverflow.com/questions/3846338/how-to-crop-an-image-in-android . – clement Jan 09 '12 at 10:38
  • no, I don't want to crop the image and the image have the same dimension of the screen...Now I try the Joru method.... – MimmoG Jan 09 '12 at 10:49
  • It's the best issue for what you want, otherwise, you just don't crop it and put the "wrap content" 's – clement Jan 09 '12 at 10:51
  • if you use wrap_content, it would say that the zone where you can put an image is all the space available. Now, if you have 100*100px available and that your picture is 10*10, you can crop it to 100*100 or let it at 10*10... Now the 100*100 depend on the device so ... – clement Jan 09 '12 at 11:14
-2
public class ScreenWidthImgView extends ImageView {

    public ScreenWidthImgView(Context context) {
        super(context);
        setScaleType(ScaleType.FIT_XY);
    }

    public ScreenWidthImgView(Context context, AttributeSet attrs) {
        super(context, attrs);
        setScaleType(ScaleType.FIT_XY);
    }

    public ScreenWidthImgView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        setScaleType(ScaleType.FIT_XY);
    }

    @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        Drawable d = getDrawable();
        int width = MeasureSpec.getSize(widthMeasureSpec);
        int height = width * d.getIntrinsicHeight() / d.getIntrinsicWidth();
        setMeasuredDimension(width, height);
    }
}

Using this ImageView with layout_width="match_parent" and layout_height="wrap_content" will give you an image that always takes up the full width of the screen and scales the image uniformly.

Joru
  • 4,406
  • 1
  • 19
  • 13