基于XML属性部分,我在下面指定了以下内容dimens.xml:
<dimen name="match_parent">-1dp</dimen>
<dimen name="main_left_menu_user_account_width">@dimen/match_parent</dimen>
<dimen name="main_left_menu_user_account_height">@dimen/match_parent</dimen>
Run Code Online (Sandbox Code Playgroud)
然后我在布局中使用这两个维度:
<ImageView
android:id="@+id/userAccountImage"
android:background="@drawable/user_account"
android:layout_width="@dimen/main_left_menu_user_account_width"
android:layout_height="@dimen/main_left_menu_user_account_height" />
Run Code Online (Sandbox Code Playgroud)
然后,当我预览到时Graphical Layout,它会抱怨:
您必须提供layout_width属性.
您必须提供layout_height属性.
实际上我可以定义一个等于match_parent的值dimens.xml吗?
更新:
我也试过了,但预览仍然抱怨:
<dimen name="main_left_menu_user_account_width">-1dp</dimen>
<dimen name="main_left_menu_user_account_height">-1dp</dimen>
Run Code Online (Sandbox Code Playgroud)
我成功使用wrap_content(Graphical Layout根本没有抱怨):
<dimen name="wrap_content">-2dp</dimen>
<dimen name="main_right_menu_width">@dimen/wrap_content</dimen>
<dimen name="main_right_menu_height">@dimen/wrap_content</dimen>
Run Code Online (Sandbox Code Playgroud)