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
Asked
Active
Viewed 303 times
1
-
1make two folder in res/layout.nexus 7 for layout-large-tvdpi,samsung 10.1 layout-xlarge-mdpi. – Hemantvc May 13 '13 at 05:14
-
@Hemant : i will try your nice comment. tx – Arash GM May 13 '13 at 05:28
2 Answers
1
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
}

Arpit Patel
- 1,561
- 13
- 23
-
+1 thank you for your quick answer.i knew that i could get device inches as u mention,but it takes long long time to make conditions for each layout for such a complete app! do u have more faster way to solve the issue? – Arash GM May 13 '13 at 05:18
-
just you need to write this code in one base activity or any Util class and pass the context. Why you are thinking of writing this code in every class? I have used this in one Util class only and check the condition. Let me edit that.... – Arpit Patel May 13 '13 at 05:21
-
if i get your idea well ,i should check this flag whenever i set a layout? so i should check this for every fragments and classes in my app? – Arash GM May 13 '13 at 05:27
-
ya you have to other wise you can also go for different layouts as well. – Arpit Patel May 13 '13 at 06:26
-
my problem solved and i've made it by making two layout folders , my big mistake was that i didn't know the proper dpi of devices. – Arash GM May 24 '13 at 13:09
0
Solved : i have made two layout folders layout-tvdpi for Nexus 7 and layout-mdpi for Samsung galaxy tab 7

Arash GM
- 10,316
- 6
- 58
- 76