Skypanther Studios
  • Home
  • Door2Door
  • About

Is your Titanium app running on a tablet?



On a recent Titanium Mobile project, I found my app’s layout got all screwy when running on an Android tablet. To be more precise, on 10-inch class tablets (like the Xoom or ASUS Transformer), buttons and other elements were not positioned correctly. For whatever reason, the 7-inch tablets seemed to be fine.

The problem is probably caused by use of percentage-based widths and placement. I should have spent time tracking down the exact root of the problem. Instead, I copped out and wrote a JavaScript module that detects when code is running on a tablet. Then I used that info to tweak the positioning of elements.

Head on over to https://github.com/skypanther/ScreenSizes to view the code. This module provides three functions:

  • isTablet() returns true if you’re running on a tablet (iPad, larger Android tablets)
  • osname() returns a string, either the result of Ti.Platform.osname (for iOS devices and Android “phones”) or “androidtablet” if you’re on a larger Android tablet
  • screensize() returns the diagonal screensize in inches.

You’ll see I made the somewhat arbitrary choice that the cut off point between an Android “tablet” and phone is 8” diagonally. You can pass in an alternate size if you’d like.

See the app.js file for example code for implementing the module. Here’s a screenshot from the Android emulator running Android 3.0/WXGA (Galaxy 10” tab emulation).

Titanium
SHARE THIS Twitter Facebook Delicious StumbleUpon E-mail
← Scaling the Android emulator
ADB hung? Restart it without closing the emulator →

No Comments Yet

Leave a Reply Cancel reply

You must be logged in to post a comment.

Tweets

  • Could not connect to Twitter

Recent Posts

  • Breakpoint debugging an Alloy app
  • Titanium graphs with a WebView
  • See the Mac Console for full error details
  • Split window editing in TiStudio
  • Delete a member of an array

EvoLve Pro theme by Theme4Press  •  Powered by WordPress Skypanther Studios
Empowering a mobile world