Value equals to match_parent or fill_parent in dimens.xml?

前端 未结 6 683
春和景丽
春和景丽 2020-12-08 00:12

Based on here on XML Attributes section I specify following in my dimens.xml:

-1dp


        
6条回答
  •  难免孤独
    2020-12-08 00:40

    Depending on why you want to define match_parent in a @dimen, this use case could help you:

    Instead of defining the width and height in dimen.xml, you can define it as a style in the styles.xml

    I use

    //res/values/styles.xml
    
    

    and

    //res/values-sw600dp/styles.xml
    
    

    and use it like

    
    

    which allows me to dynamically set the width and height attributes for different sized devices without having to write any code and you can use match_parent/wrap_content fine. you can use any @dimen that you have defined previously in the style as well if you want.

    I use this because the layout for phone and tablet is the same, except i want to fix the width on tablet but fill the parent on phone, so it saves having to have 2 different layouts with basically the same xml

提交回复
热议问题