android - Differerentiate layout for two devices with same dpi -
i have 2 layout folder: layout-sw800dp , layout-sw600dp app use layout-sw600dp both devices , samsung galaxy tab 7 , nexus 7,and makes fonts , styles bigger nexus 7! how can differentiate layout 2 devices? in advance
you can check 10 , 7 inch table screen size following code
displaymetrics metrics = new displaymetrics(); getwindowmanager().getdefaultdisplay().getmetrics(metrics); float widthininches = metrics.widthpixels / metrics.xdpi; float heightininches = metrics.heightpixels / metrics.ydpi; double sizeininches = math.sqrt(math.pow(widthininches, 2) + math.pow(heightininches, 2));
here sizeininches gives proper inch of table take 0.5 inch in buffer , give condition according below.
boolean is7inchtablet = sizeininches >= 6.5 && sizeininches <= 7.5;
and whenever need check check below.
if(is7inchtablet){ // whatever 7-inch tablet }else{ // whatever 10-inch tablet }
Comments
Post a Comment