我想指定 drawable
的宽度/高度在dp
使用变量
喜欢:
<dp name="width">30</dp>
当使用 width
时:
android:layout_width=width
就像在说 android:layout_width="30dp"
有什么办法吗?
最佳答案
在 dimens.xml
中创建您的 dp
值,如下所示:
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="width">16dp</dimen>
</resources>
并使用
<ImageView
android:layout_width="@dimen/width"
android:layout_height="match_parent" />
关于android - 是否可以在 xml 中创建一个 "dp"变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51033561/