如何在Android

时间:2018-07-01 11:33:28

标签: java android android-layout

在我的应用程序中,我想使用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

1 个答案:

答案 0 :(得分:1)

您的宽度尺寸需要一个单位

120本身是没有意义的。您可能想要120dp。 dp是物理测量的单位,与分辨率无关,这就是android保持与不同设备的兼容性的方式。

EG:

<dimen name="size120New">120dp</dimen>

还有其他单位,这个答案很好地解释了: https://stackoverflow.com/a/2025541/2762277