在我的应用程序中我想使用 RelativeLayout
为了将 size 设置为此,我使用 dimens
.
我编写的 XML 代码如下所示:
<RelativeLayout
android:id="@+id/listItemAuction_productImgLay"
android:layout_width="@dimen/size120New"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginBottom="@dimen/padding5"
android:layout_marginRight="@dimen/padding5"
android:layout_marginTop="5dp">
</RelativeLayout>
尺寸: <dimen name="size120New">120</dimen>
但是当运行应用程序时,在 Logcat
上向我显示下面的错误 :
java.lang.RuntimeException: Binary XML file line #26: You must supply a layout_width attribute.
我该如何修复它以及我们dimes
?
最佳答案
您的宽度尺寸需要一个单位
120 本身是没有意义的。您可能想要 120dp。 dp 是一种物理测量单位,与分辨率无关,这就是 Android 保持与不同设备兼容性的方式。
EG:
<dimen name="size120New">120dp</dimen>
还有其他单位,这个答案解释得很好: https://stackoverflow.com/a/2025541/2762277
关于java - 如何修复 Android 中提供的layout_width属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51122906/