简体   繁体   中英

android dimens value for different resolution devices

I want setup different dimen-values for different resolution(dp) devices, how ?

just in my dimens.xml

 <resources>

    <!-- for 1280x720 dp ,Default screen margins, per the Android Design guidelines. -->

    <dimen name="image_thumbnail_size">200dp</dimen>
    <dimen name="image_thumbnail_spacing">2dp</dimen>
    <dimen name="image_detail_pager_margin">160dp</dimen>
    <dimen name="activity_horizontal_margin">80dp</dimen>
    <dimen name="activity_vertical_margin">100dp</dimen>

    <!--  for 640x360 dp -->
<!-- 
        <dimen name="image_thumbnail_size">100dp</dimen>
    <dimen name="image_thumbnail_spacing">2dp</dimen>
    <dimen name="image_detail_pager_margin">80dp</dimen>
    <dimen name="activity_horizontal_margin">40dp</dimen>
    <dimen name="activity_vertical_margin">30dp</dimen>
     -->

add: I have two devices, the resolution is 1280x720 ,but my phone dp is 640x360 , and another is 1280x720

Create seperate values folders, each with a different suffex. Some examples:

values-normal (for phone versions)
values-large (for 7" tablets)
values-xlarge (for large tablets)

Place a dimensions.xml file in each of these folders, in each one, specify different values for each variable.

Hope this helps.

Sorry to get this to you late but you can use the same folder combinations that you use for drawables with the values folder. Here is an example

values-ldpi/dimens.xml
values-hdpi/dimens.xml
values-xhdpi/dimens.xml

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM