Dimensions

 

Dimensions are used in several places in Android to describe distances, such as a widget’s padding. While this book usually uses pixels (e.g., for ten pixels), there are several different units of measurement available to you:

• and for inches and millimeters, respectively, based on the actual size of the screen

• for points, which in publishing terms is 1/72nd of an inch (again, based on the actual physical size of the screen)

• and for device‑independent pixels and scale‑independent pixels – one pixel equals one dp for a 160dpi resolution screen, with the ratio scaling based on the actual screen pixel density (scale‑independent pixels also take into account the user’s preferred font size)

To encode a dimension as a resource, add a element, with a name attribute for your unique name for this resource, and a single child text element representing the value:

 

 

In a layout, you can reference dimensions as , where the ellipsis is a placeholder for your unique name for the resource (e.g., thin and fat from the previous sample). In Java, you reference dimension resources by the unique name prefixed with (e.g., ).

 

Colors

 

Colors in Android are hexadecimal RGB values, also optionally specifying an alpha channel.

You have your choice of single‑character hex values or double‑character hex values, leaving you with four styles:

These work similarly to their counterparts in Cascading Style Sheets (CSS).

You can, of course, put these RGB values as string literals in Java source or layout resources. If you wish to turn them into resources, though, all you need to do is add color elements to the resources file, with a name attribute for your unique name for this color, and a single text element containing the RGB value itself:

 

In a layout, you can reference colors as , replacing the ellipsis with your unique name for the color (e.g., ). In Java, you reference color resources by the unique name prefixed with (e.g., ).

 

Arrays

 

Array resources are designed to hold lists of simple strings, such as a list of honorifics (Mr., Mrs., Ms., Dr., etc.).

In the resource file, you need one string‑array element per array, with a name attribute for the unique name you are giving the array. Then, add one or more child item elements, each of which have a single text element with the value for that entry in the array:

 

From your Java code, you can then use to get a of the items in the list. The parameter to is your unique name for the array, prefixed with (e.g., ).

 

 








Дата добавления: 2015-05-16; просмотров: 681;


Поиск по сайту:

При помощи поиска вы сможете найти нужную вам информацию.

Поделитесь с друзьями:

Если вам перенёс пользу информационный материал, или помог в учебе – поделитесь этим сайтом с друзьями и знакомыми.
helpiks.org - Хелпикс.Орг - 2014-2024 год. Материал сайта представляется для ознакомительного и учебного использования. | Поддержка
Генерация страницы за: 0.006 сек.