Solved : i have made two layout folders layout-tvdpi for Nexus 7 and layout-mdpi for Samsung galaxy tab 7
Differerentiate layout for two devices with same dpi
-
21-04-2022 - |
Pregunta
i have two layout folder: layout-sw800dp and layout-sw600dp so my app use layout-sw600dp for both devices , Samsung Galaxy Tab 7 and Nexus 7,and it makes my fonts and styles bigger for Nexus 7! how can i differentiate layout for this two devices? Thanks in Advance
Solución 2
Otros consejos
you can check the 10 and 7 inch table screen size from the 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 you the proper inch of the table take 0.5 inch in buffer and give condition according to it like below.
boolean is7inchTablet = sizeInInches >= 6.5 && sizeInInches <= 7.5;
And whenever you need to check it just check as below.
if(is7inchTablet){
// do whatever for the 7-inch tablet
}else{
// do whatever for the 10-inch tablet
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow