How to use dimens.xml in Android?

前端 未结 6 2010
没有蜡笔的小新
没有蜡笔的小新 2020-11-30 01:01

When I design a layout, I centralize all dimensions in dimens.xml because of topics of maintainability. My question is if this is correct or not. What would it be the best g

6条回答
  •  日久生厌
    2020-11-30 01:53

    @Jesús Castro You are doing it right. Maintaining values in the dimens.xml file is better than littering hardcoded values around in all your layout files.

    For example, imagine the case where you to increase the left and right margins in all your view. If you used a single value maintained in dimens.xml, this would be a quick change - a single value in a single file. However, if you had put the margin values as a literal values such as "16dp" in your layout files (instead of using a dimens value like "@dimen/leftright_margin"), you have to go edit each layout file which is error prone and just plain time consuming.

提交回复
热议问题