Friday 15 May 2015

Android resize buttons for different resolutions scale layout -


Is this a good way for all Android devices? I have an image view as a background, and I change it according to the resolution of the Android device.

  Private bitmap getResizedBitmap () {bitmap size changed bitmap; Bitmap BMP = bitmapfichture Decode resources (getResources (), randomwhitebackground_3ball); X640 = bmp.getWidth (); Y960 = bmp.getHeight (); If (screen retro & gt; ratio organs) {imageWidth = (int) ((double) y960 * wide main / heighten); ImageHeight = y960; Int x = (x640-imageWidth) / 2; ResizedBitmap = Bitmap.creditbetaMap (BMP, X, 0, Imagewidth, ImageHit); } And if (Screenshots; Lt; ratio;) {imageWidth = x640; ImageHeight = (int) ((double) x640 * heightMain / widthMain); Int y = (y960-imageHyight) / 2; ResizedBitmap = Bitmap.creditBitMap (BMP, 0, Y, Imagewidth, ImageHit); } And {return BMP; } Tw.setText (widthMain + "\ n" + Altman + "\ n" + imageWidth + "\ n" + ImageHight); Returns were resized; Bitmap; } Private Zero SetBackground () {DisplayMetrics metric = new performance metrics (); . GetWindowManager () getDefaultDisplay () getMetrics (matrix). WidthMain = Matrix.With Pixel; Height i = metrics High pixel; ScreenRatio = ((double height height) / width; Bitmap resized bitmap = bitmap size matching (); ImageBackground.setImageBitmap (resizedBitmap); }   

Using a DP or another thing the image looks bad, for example, I have an incision in backgound and it looks like an aliens while scaling automatically < Pre> For example, in my image there are dimensions of 640x960 RatioOrginal 960: 640 = 1.5 If a device is mdpi and 320x480 screenRatesto = 480/320 = 1.5 is the dimension and it's fine. But if it is mdpi and 480x800 screenshot = 900/480 does not have dimension 1.5. Both are MDPIs, but the ratio is not standard. I can not understand how people do this in support of many screens, there is an XML for MDPI how it receives different resolutions.

I recommend using it instead.

Use Android DP and create various layout files for different screen sizes.



No comments:

Post a Comment