AFAIK there is no way you could be sure that you are in front of a table
or a phone (or a TV). Bear in mind that in the future there may be even
other different device types.
You better rely on screen density and/or resolution to calculate the
font size. That's what I do on my last casual game -still unpublished-.
So, if you use a size of 10 for an screen that is 800 pixels height, you
may use a size of 20 for an screen that is 1600 pixels height.
So you can do something like:
realFontSize = (getWindowManager().getDefaultDisplay().getHeight() * 10)
/ 800
Anyway I think it should be a more straightforward native way to do this
in most cases using dp or so, but I am not sure about.
Hope a more advanced Android developer could give you a better answer,
but in the meantime you can use that code as a workaround.
Regards,
On 26/07/12 13:07, |-NK-| wrote:
> Hi
>
> I am developing an application that can be used on android phone and
> tablets.
>
> I have a UI on which I need to generate buttons on screen dynamically.
>
> I set font size of these buttons to 10 for phone devices, and it
> looked fine.
> But when I ran same for Tablet , the font was small and the buttons
> size too.
>
> I am using same class for handling UI on both tablet and phone, but
> using different layout xml files for tablet and phone.
>
> How can I find out which device am I using, so that I can set the
> button properties depending upon devices.
>
> I need to do something similar to this
>
> int size;
> if(device == Tablet)
> {
> size = 20;
> }
> else if(device == phone)
> {
> size = 10;
> }
>
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en