Reputation: 13752
i create an android application to support both mobile android phone and galaxy tab, i need to align the text dynamically , it is mobile version (layout-small) i need to set the text for Text view dynamically as " mobile phone " , else if it is samsung galaxy tab or some other android tab , i need to dynamically set the text as " Galaxy Tab".
If any one know the solution help me out?
Thanks.
Upvotes: 3
Views: 961
Reputation: 52002
Another option is to check for the screen size classifier:
int mask = Configuration.SCREENLAYOUT_SIZE_MASK;
int size = context.getResources().getConfiguration().screenLayout;
if ((size & mask) == Configuration.SCREENLAYOUT_SIZE_XLARGE) {
// Screen is classified x-large
}
You can use the same method to check for other screen sizes by using different values for the Configuration flag.
Upvotes: 3
Reputation: 11571
You can use this function to dynamically determine the width of the device:
int screenWidth=getWindowManager().getDefaultDisplay().getWidth();
if the width>480 than it must be tab otherwise the device is android phone. Using this you can set the text dynamically according to the screenWidth.
Upvotes: 0
Reputation: 6167
Build.Model should tell you what model the device is.
(Alternatively, you could look at DisplayMetrics to get the screen size/resolution, which won't tell you the exact model, but will tell you whether you want your small or large layout.)
Upvotes: 1