https://kotlinlang.org logo
Title
o

oday

09/12/2018, 2:14 PM
not much to do with Kotlin and Android together, but just Android, how do you organize your dimens.xml? I was thinking of having preset numbers from 10 to X, with 10 and 5 intervals in between
r

rharter

09/12/2018, 3:18 PM
Those would got directly in the layout for me, because 10dp isn't different on a tablet, or in landscape mode. If you're putting
@dimen/10dp
in your layouts, then it's really the same as
10dp
. dimens.xml is more for things that will change based on configuration, like
list_margin_horizontal
or
item_title_padding_left
or
list_item_height_standard
.
👍 1
o

oday

09/12/2018, 4:41 PM
You're saying that dimens.xml is useless if you only allow one configuration portrait for your app? For example?
d

dan.the.man

09/12/2018, 5:39 PM
No because there are still different sized phones. The dimensions should be set for each item, like
home_button_margin
and so then if you ever want to change your home button margin that's doable from within your styles, not in the XML files themselves
r

rharter

09/12/2018, 6:16 PM
What I'm saying is that dimens.xml is useful for two things, dimensions that might change with configuration, and dimensions that are shared, like style guide elements. If you only have a single home_button, then I would hard code the
home_button_margin
. If that's used in several places throughout your app, I would make a dimen.
What's more, I like to think of things like card dimensions. If you have a styleguide that says your card padding is 8dp and your card corner radius is 2dp, that's a good place for a dimen, since it's used throughout the app. Then when Material2 comes out with card radii of 8dp, you update the dimen and all of your cards get the new corner radius.
o

oday

09/13/2018, 7:08 AM
good points @rharter, and I agree that even if you have a
home_button_margin
you won’t be able to give it such a name as to know what this dimen refers to exactly, you’re always going to go to the XML first and see what dimension that button has, before going to dimens.xml, it’s not like your Constants file, there’s simply too many dimens to be able to name them so well that you dont even have to look at XML first