How do I avoid this hardcoded math...
<resources> <dimen name="uno">10dip</dimen> <dimen name="dos">6dip</dimen> <dimen name="uno_plus_dos">16dip</dimen> </resources> <Button android:layout_marginTop="@dimen/uno_plus_dos" />
...and covert it to something like this?
<Button android:layout_marginTop="@dimin/uno + @dimen/dos" />
A dimension is specified with a number followed by a unit of measure. For example: 10px, 2in, 5sp. The following units of measure are supported by Android: dp.
To create another dimens. xml file, right click your res folder and choose New > Value resource file. Then write in dimens and choose Smallest Screen Width. Write in 600 for the width (7” tablet).
You don't, sorry. Layout XML files do not support expressions. You either:
@dimen/uno_plus_dos
, orUPDATE The data binding library supports some operations in its expressions. I am uncertain if it can handle this specific scenario.
One trick for simple addition is to use margin + padding.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With