How to stretch an image in Android to fullscreen while maintaining aspect ratio?
As stated in the title I'm having trouble with the first step, which is stretching the image to the screen's resolution. My second problem is maintaining aspect ratio while stretching the image.
My code:
TwoDimensionalSprite _2dBckgrndSprite = new TwoDimensionalSprite开发者_运维问答(_parentScreen.getContext());
_2dBckgrndSprite.setImageResource(R.drawable.oh);//old-house
_2dBckgrndSprite.setLayoutParams(new Gallery.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
_parentScreen.AddElement(_2dBckgrndSprite);
I know of the method setScaleType and I have tried it aswell but nothing seems to work.
Use ScaleType:
http://developer.android.com/reference/android/widget/ImageView.ScaleType.html
using imgview.setScaleType(ScaleType.FIT_XY);
will make the image fit exactly on device.
精彩评论