开发者

How to determine Android or galaxy tab?

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.


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.


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.)


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜