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?

Community
  • 1
  • 1
Abhi
  • 433
  • 2
  • 7
  • 17

1 Answers1

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

Bhanu Sharma
  • 5,135
  • 2
  • 24
  • 49
  • 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 05 '14 at 06: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 :) – Bhanu Sharma Mar 05 '14 at 06: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 – Bhanu Sharma Mar 05 '14 at 06: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 05 '14 at 07:04
  • abhi u have to make diff diff drawable for it dude and just set that in java class with like height and width, margin – Bhanu Sharma Mar 05 '14 at 07:06
  • like drawable-hdpi, drawable-large, drawable-ldpi, drawable-xhdpi, drawable-xlarge-mdpi and so on drawable-sw600dp,drawable-sw720dp and put all images in their folder and then set all images in java code – Bhanu Sharma Mar 05 '14 at 07:09
  • in oncreate method only after set layout and findviewbyid of all view – Bhanu Sharma Mar 05 '14 at 07:22
  • Which variable is this metrics? – Abhi Mar 05 '14 at 08:38
  • Hey Bhanu plzzzz reply – Abhi Mar 05 '14 at 08:42
  • 1
    private DisplayMetrics metrics; metrics = new DisplayMetrics(); – Bhanu Sharma Mar 05 '14 at 08:47
  • and what are these variables imageWidth etc? – Abhi Mar 05 '14 at 09:09
  • private int imageWidth,imgHeight,margin; – Bhanu Sharma Mar 05 '14 at 09:12
  • ohk now u declare dude just chill – Bhanu Sharma Mar 05 '14 at 09:24
  • dear what if i need to adjust particular images width and height? – Abhi Mar 05 '14 at 09:31
  • u can only set imageview width and height dude just take that reference(findviewbuid) and use but i think dont take it hardcode just use diff size of images – Bhanu Sharma Mar 05 '14 at 09:51
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/49035/discussion-between-bhanu-sharma-and-abhi) – Bhanu Sharma Mar 05 '14 at 09:51