相对布局,最佳实践评估顺序和相对布局解析 [英] Order of evaluation with relative layouts, best practices and parsing of relative-layout

查看:273
本文介绍了相对布局,最佳实践评估顺序和相对布局解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读到这


它曾经是Android的会使用单次处理
RelativeLayout的定义的规则。这意味着你不能引用部件
(例如,通过机器人:layout_above),直到它已在XML声明。这个
做定义一些布局有点复杂。在Android 1.6的开始,
Android使用两遍处理规则,所以你现在可以安全地让
作为至今没有未定义的部件向前引用。

" 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. "

我不知道是什么问题,也许是日食的问题,但即使我用2.3我仍然有问题,当我引用未声明喷一些人认为这对我来说似乎是Android不采用两道工艺的规则相对布局

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.

请注意:我总是用@ + ID / WIDGET_NAME当我宣布窗口小部件并@ ID / WIDGET_NAME当我引用来自其他部件的部件。我注意到,我可以使用@ + ID / WIDGET_NAME甚至当我只想引用一个小部件。我想这是错误的,但为什么有时候是工作没有任何投诉?在我看来,一个构件,应允许被宣布为唯一...

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...

我的问题是真的是Android使用两遍?我需要与相对布局工作的一些准则(最佳做法)

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

感谢

推荐答案

@ + ID /名称创建一个新的ID,如果它不存在。 @ ID /名称引用现有的ID,也永远不会创建一个。

@+id/name creates a new id, if it doesn't already exist. @id/name references an existing id, and will never create one.

我不知道是否可以使用 @ ID /名称 @ + ID /名称在相同的文件。如果没有,我能想到的两种解决方法的:

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:


  1. 总是使用 @ + ID /名称

定义所有的ID在 ids.xml 文件,并始终使用 @ ID /名称

Define all id's in the ids.xml file, and always use @id/name.

这篇关于相对布局,最佳实践评估顺序和相对布局解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆