Search this blog

How to work with Dimensions in android

To specify the size of a user interface control such as a Button or TextView control,you need to specify different kinds of dimensions. You tag dimension resources with the <dimen> tag and store them in the resource file /res/values/dimens.xml. This XML resource file is not created by default and must be created manually.

Here is an example of a dimension resource file:
<?xml version=”1.0” encoding=”utf-8”?>
<resources>
<dimen name=”thumbDim”>100px</dimen>
</resources>
Each dimension resource value must end with a unit of measurement. Given below is the  list that shows the dimension units that Android supports.


Type of Measurement        Description                           Unit String
Pixels                                 Actual screen pixels                     px
Inches                                Physical measurement                 in
Millimeters                          Physical measurement                 mm
Points                                Common font measurement          pt
Density-independent pixels  Pixels relative to 160dpi                dp
Scale-independent pixels     Best for scalable font display         sp









0 comments:

Post a Comment