Tonton MyTV dilengkapi intisari rancangan pada smart TV bermula RM4.99 sebulan. Selanjutnya →

Designing web page for Android webview

Selasa, 6 November 2012, 9:31 pm0

Android screen built-in resolutions (based on API 8-16):

SkinResolution (w x h pixel)Orientation
QVGA240 x 320Portrait
WQVGA400240 x 400Portrait
WQVGA432240 x 432Portrait
HVGA320 x 480Portrait
WVGA800480 x 800Portrait
WVGA854480 x 854Portrait
WSVGA1024 x 600Landscape
WXGA7201280 x 720Landscape
WXGA, WXGA800, WXGA800-7in1280 x 800Landscape

Android screen density

DensityDPI / Pixel ratioSkin
ldpi120 / 0.75QVGA, WQVGA400, WQVGA432
mdpi160 / 1.0HVGA, WSVGA, WXGA
tvdpi213 / 1.33125WVGA800-7in
hdpi240 / 1.5WVGA800, WVGA854
xhdpi320 / 2.0WXGA720, WXGA800

Android webview viewport size (100% width and height)

SkinViewport (w x h pixel, portrait)
QVGA320 x 427
WQVGA400320 x 533
WQVGA432320 x 576
HVGA320 x 480
WVGA800320 x 533
WVGA854320 x 569
WSVGA600 x 1024
WXGA720360 x 598
WXGA800 x 1280
WXGA800400 x 598
WXGA800-7in601 x 962

In the HTML page, make sure we lock the webpage from being resize/zoom

<meta name="viewport" content="width=device-width,user-scalable=no,initial-scale=1" />

To design responsive web page, pay attention to webview viewport size in writing the css media query. From the viewport size table above, if we’re designing for portrait orientation only, we have a set of widths: 320, 360, 400, 600, 800 (601 can use 600 width styles). So our css code must be organized like this:

/* width: 800 */
.container { width: 800px; }

/* width: 600 */
@media (max-width: 799px) {
    .container { width: 600px; }
}

/* width: 400 */
@media (max-width: 599px) {
    .container { width: 400px; }
}

/* width: 360 */
@media (max-width: 399px) {
    .container { width: 360px; }
}

/* width: 320 */
@media (max-width: 359px) {
    .container { width: 320px; }
}

Note: Since landscape width got more, choose widths that can be grouped together, e.g: 420, 480, 530, 960, 1024, 1280

In handling different screen density using css, it’s recommended to display images as background of html elements.
HTML:

<i class="icon ok"></i>

CSS:

.icon {
    width: 50px;
    height: 50px;
    display: block;
    background-size: 50px 50px;
}
.icon.ok {
    background-image: url(img/mdpi/icon_ok.png);
}

That’s for the base density (mdpi). For other densities:

/* density: xhdpi */
@media screen and (-webkit-device-pixel-ratio: 2.0) {
    .icon.ok { background-image: url(img/xhdpi/icon_ok.png); }
}

/* density: hdpi */
@media screen and (-webkit-device-pixel-ratio: 1.5) {
    .icon.ok { background-image: url(img/hdpi/icon_ok.png); }
}

/* density: ldpi */
@media screen and (-webkit-device-pixel-ratio: 0.75) {
    .icon.ok { background-image: url(img/ldpi/icon_ok.png); }
}

Note: for tvdpi, it’ll use hdpi stylesheet & resize accordingly.

Image sizes. To know what image size you need, use pixel ratio to resize the image (base design is using 1.0 pixel ratio). Image DPI (dot per inch) is 72. E.g:

Image fileDensity / Pixel ratioSize
img/ldpi/icon_ok.pngldpi / 0.7550 x 0.75 = 38px
img/mdpi/icon_ok.pngmdpi / 1.050 x 1.0 = 50px
img/hdpi/icon_ok.pnghdpi / 1.550 x 1.5 = 75px
img/xhdpi/icon_ok.pngxhdpi / 2.050 x 2.0 = 100px

OOP the right way

15 November 2012

Twitter Bootstrap resources

19 September 2012

Tulis komen: