How can I specify different layout sizes for different densities

Could you tell me how I can determine the size of the layout for different screen densities? that is, the layout is the same for different densities, but some measurements are different. How can i do this?

Thank.

+3
source share
3 answers
//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.
+11
source

you define the layout and place it under

Res / Layout Classifier / my _layout.xml
where Qualifier can be one or more of the following

size: small, normal, large

density: ldpi, mdpi, hdpi.

For example, the layout for a large screen with a high density would be res / layout-hdpi-large / my_layout.xml

See the answer above for a complete list of attributes.

+2

You can use different units of measurement to adapt the size to the screen.

Available units: px (pixels), dp (density-independent pixels), sp (scaled pixels based on the preferred font size), in inches, mm (millimeters).

Available Resource Types

Multi screen support

0
source

Source: https://habr.com/ru/post/1745491/


All Articles