本文介绍了值等于match_parent或FILL_PARENT在dimens.xml?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
基于此XML的属性部分我指定我<$ C以下$ C> dimens.xml :
&LT;扪名=match_parent&GT; -1dp&LT; /扪&GT;
&LT;扪名=main_left_menu_user_account_width&GT; @扪/ match_parent&LT; /扪&GT;
&LT;扪名=main_left_menu_user_account_height&GT; @扪/ match_parent&LT; /扪&GT;
然后,我用两个维度在我的布局:
&LT; ImageView的
机器人:ID =@ + ID / userAccountImage
机器人:背景=@可绘制/ user_account
机器人:layout_width =@扪/ main_left_menu_user_account_width
机器人:layout_height =@扪/ main_left_menu_user_account_height/&GT;
然后,当我preVIEW到图形布局
时,报告说:
其实我可以定义一个值等于 dimens.xml
?
更新:
我也试过,但在preVIEW仍然抱怨:
&LT;扪名=main_left_menu_user_account_width&GT; -1dp&LT; /扪&GT;
&LT;扪名=main_left_menu_user_account_height&GT; -1dp&LT; /扪&GT;
我成功地使用 WRAP_CONTENT
(即图形布局
不抱怨的话):
&LT;扪名=WRAP_CONTENT&GT; -2dp&LT; /扪&GT;
&LT;扪名=main_right_menu_width&GT; @扪/ WRAP_CONTENT&LT; /扪&GT;
&LT;扪名=main_right_menu_height&GT; @扪/ WRAP_CONTENT&LT; /扪&GT;
解决方案
使用此,它为我的作品
&LT;整数NAME =custom_wrap_content&GT; -2&LT; /整数GT;
&LT;扪名=horizontal_border_height&GT; @整数/ custom_wrap_content&LT; /扪&GT;
&LT;整数NAME =custom_match_parent&GT; -1 LT; /整数GT;
&LT;扪名=vertical_border_height&GT; @整数/ custom_match_parent&LT; /扪&GT;
Based on here on XML Attributes section I specify following in my 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>
Then I use the both dimensions in my layout:
<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" />
Then, when I preview to Graphical Layout
, it complains:
Actually can I define a value equals to match_parent in dimens.xml
?
Update:
I also tried this but the preview still complains:
<dimen name="main_left_menu_user_account_width">-1dp</dimen>
<dimen name="main_left_menu_user_account_height">-1dp</dimen>
I successfully use wrap_content
(the Graphical Layout
doesn't complain at all):
<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>
解决方案
Use this, it works for me
<integer name="custom_wrap_content">-2</integer>
<dimen name="horizontal_border_height">@integer/custom_wrap_content</dimen>
<integer name="custom_match_parent">-1</integer>
<dimen name="vertical_border_height">@integer/custom_match_parent</dimen>
这篇关于值等于match_parent或FILL_PARENT在dimens.xml?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!