How can I specify different dimension of layout for different density
Can you please tell me how can I specify dimension of layout for different de开发者_如何转开发nsity of screen? i.e. the layout are the same across different densities, but some dimension are different. how can I do that?
Thank you.
//1.create different dimens.xml in different resource folders as below
res/values-ldpi/dimens.xml
res/values-mdpi/dimens.xml
res/values-hdpi/dimens.xml
//Then Android will decide which file to use.
//2.Create dimensions values in respective dimens.xml file according to the need as below
<!-- in values-ldpi/dimens.xml -->
<dimen name="textSize">25dip</dimen>
// and..
<!-- in values-mdpi/dimens.xml -->
<dimen name="textSize">20dip</dimen>
// etc.
// 3.Don't care about resolution Android will take care of which resource to fetch.
// 4.Mention size in dp instead of pixels.
you define you layout and put it under
res/layout-Qualifier/my_layout.xml
where Qualifier could be one or more of the following
size : small, normal, large
density: ldpi,mdpi, hdpi.
For example layout for large screen with high density would be res/layout-hdpi-large/my_layout.xml
For full list of attributes see answer above
You can use different units to have the dimensions adapt to the screen.
Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters).
Available Resource Types
Supporting Multiple Screens
精彩评论