相对布局的评估顺序、最佳实践和相对布局的解析
我读到了这个
“ 以前Android会使用单遍来处理 relativelayout定义的规则。这意味着您无法引用小部件 (例如,通过 android:layout_above)直到它在 XML 中声明。这 使得定义一些布局有点复杂。从 Android 1.6 开始, Android 使用两次传递来处理规则,因此您现在可以安全地拥有 转发对尚未定义的小部件的引用。 “
我不知道问题是什么,也许是 eclipse 问题,但即使我使用 2.3,当我引用一些未声明 jet 的视图时,我仍然遇到问题,所以对我来说,android 似乎不使用两次传递来处理规则 注意:当我声明小
部件时,我总是使用 @+id/widget_name ;当我从其他小部件引用该小部件时,我总是使用 @+id/widget_name 。我注意到即使我只想使用 @+id/widget_name 。到引用那个小部件。我想这是错误的,但为什么有时可以毫无抱怨地工作?在我看来,应该只允许声明一个小部件......
我的问题是 android 真的使用两个通道吗?我需要一些指导方针(最佳实践)对于使用相对布局
我对如何进行相对布局配对有点困惑,所以欢迎任何解释
谢谢
I read this
"
It used to be that Android would use a single pass to process
RelativeLayout-defined rules. That meant you could not reference a widget
(e.g., via android:layout_above) until it had been declared in the XML. This
made defining some layouts a bit complicated. Starting in Android 1.6,
Android uses two passes to process the rules, so you can now safely have
forward references to as-yet-undefined widgets.
"
I do not know what is the problem maybe is eclipse problem, but even I use 2.3 I still have problems when I reference some view that is not declared jet so for me it seems like android doesn't uses two passes to process the rules for relative layout.
note: I always use @+id/widget_name when I declare the widget and @id/widget_name when I reference that widget from other widget. I have noticed that I can use @+id/widget_name even when I just want to reference that widget. I guess that is wrong but why sometimes is works without any complaints ? In my opinion one widget should be allowed to be declared only ones...
My questions is is really android uses two passes ? and I need some guidelines (best practices) for working with relative layouts
I am little confused about how this relative layout parings are made, so any explanations are welcomed
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
@+id/name
创建一个新的 id(如果它尚不存在)。@id/name
引用现有的 id,并且永远不会创建一个。我不确定您是否可以在同一文件中的
@+id/name
之前使用@id/name
。如果没有,我可以想到两种解决方法:始终使用
@+id/name
。在
ids.xml
文件中定义所有 id,并始终使用@id/name
。@+id/name
creates a new id, if it doesn't already exist.@id/name
references an existing id, and will never create one.I'm not sure if you can use
@id/name
before@+id/name
in the same file. If not, I can think of two workarounds:Always use
@+id/name
.Define all id's in the
ids.xml
file, and always use@id/name
.此是有关 Android 如何绘制视图的一般信息。
我认为Android会两次遍历所有视图,但不会遍历每个视图一次。因此,如果您有从一个 xml 到另一个 xml 的引用,它总是可以正常工作,但如果您在单个 xml 内有引用,则必须小心地正确排序 xml 中的元素。例如,我的RelativeLayout中有view1和view2。如果我想从 view1 引用 view2,我必须在 view1 之前声明 view2。
This is general information on how Android draw views.
I think that Android passes twice through all the view, but it doesn't pass through each single view once. So if you have a reference from one xml to another it will always work fine, but if you have references inside a single xml you must be carefull to order the elements in the xml correctly. For example, I have view1 and view2 in my RelativeLayout. If I want to refer to view2 from view1 I must declare view2 before view1.