How do I apply mathematical operations to Android dimensions?

前端 未结 4 1317
-上瘾入骨i
-上瘾入骨i 2020-12-24 11:05

How do I avoid this hardcoded math...


 10dip
 6dip
 

        
4条回答
  •  佛祖请我去吃肉
    2020-12-24 11:33

    You don't, sorry. Layout XML files do not support expressions. You either:

    • Leave it as @dimen/uno_plus_dos, or
    • Set your margins in Java code, where you can replace a single resource with a bunch of extra lines of code, or
    • Write your own layout preprocessor that handles expressions like this

    UPDATE The data binding library supports some operations in its expressions. I am uncertain if it can handle this specific scenario.

提交回复
热议问题