android - 是否可以在 xml 中创建“dp”变量?
问题描述
我想使用变量指定 adrawable
的宽度/高度dp
像:
<dp name="width">30</dp>
使用时width
:
android:layout_width=width
就像说android:layout_width="30dp"
有什么办法可以做到这一点?
解决方案
像下面这样创造你的dp
价值:dimens.xml
<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" />
推荐阅读
- java - 如何从静态方法打印非静态方法?
- java - Java 7中两个日期之间的年差
- php - 我的联系表格中的邮件布局有问题
- symfony - 如何在前端使用 datagrid 的导出功能
- c# - 如何创建一个给出指定列名和类型的 sql 表
- python - C++ 特征库中的 argmax() 方法
- javascript - 我无法声明的内容安全政策错误
- scala - 如果异步添加处理程序,则通过 netty 通道丢失的消息
- javascript - 使用 MSAL2 登录后验证服务器上的用户
- shell - MSB4019 使用 Github 操作运行 Xamarin Android 单元测试