Reputation: 110510
Can you please tell me how can I specify dimension of layout for different density of screen? i.e. the layout are the same across different densities, but some dimension are different. how can I do that?
Thank you.
Upvotes: 2
Views: 6077
Reputation: 6480
//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.
Upvotes: 10
Reputation: 68434
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
Upvotes: 2
Reputation: 53659
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).
Upvotes: 0