2

I have developed my app in 3.7 inch galaxy S2 with Drawable/hdpi (480x720px) now I want to design it for Micromax A54 with 3.5 inch screen 320x480px

Both are Normal screen sizes but their densities are different I have referred these tutorials

but still I am stuck is there any other way of doing like direct through coding or i am going wrong please help me?

3

1 Answer 1

0

I take one xml only and set my layout like in java class like this

int widthPixels,density,widthDp,scaleFactor ;
density= getResources().getDisplayMetrics().densityDpi;

  widthPixels = metrics.widthPixels;
  scaleFactor = metrics.density;
  widthDp = widthPixels / scaleFactor;

now i have all density width height now i set in my xml like

 if(widthDp==600)
                {
                    imageWidth = 45;
                    imgHeight = 45;
                    margin = 11;
                }
                else if (widthDp==720)
                {

                }
                else if(density==DisplayMetrics.DENSITY_XHIGH)
                {
                    imageWidth = 60;
                    imgHeight = 60;
                    margin = 17;
                }
                else if(density==DisplayMetrics.DENSITY_LOW)
                {
                    imageWidth = 30;
                    imgHeight = 30;
                    margin = 9;
                }
                else if(density==DisplayMetrics.DENSITY_MEDIUM)
                {
                    imageWidth = 40;
                    imgHeight = 40;
                    margin = 10;
                }
                else
                {
                    imageWidth = 60;
                    imgHeight = 60;
                    margin = 13;
                }

u can also set all variable which u want to set or take in your xml here i only ser height,width and margin
Best of luck dude

16
  • Hey Bhanu. is it wright way of doing coz i haven't got any kind of such technique on developers site and video tutorials both..
    – Abhi
    Mar 5, 2014 at 6:48
  • abhi developers make his/her own technique other wise it will be a just copy paste i make this my own and set 12 different layouts with this just try dude its very easy and developers site just mention how u will got density of any mob device ohk and i apply that tech in this like my code :) new ideas is always be a new technique dude just do it :) Mar 5, 2014 at 6:53
  • if u take many layout then it will be waste of code just make diff drawable folder and take diff diff images if u use images in your app then only i.e android take automatically diff images according to size of device Mar 5, 2014 at 6:55
  • I have inserted 320x480 px images for 3.5 inch Micromax a54 but these images are not picked up by my device. both the screens comes under normal screen sizes?
    – Abhi
    Mar 5, 2014 at 7:04
  • 1
    private DisplayMetrics metrics; metrics = new DisplayMetrics(); Mar 5, 2014 at 8:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.