我如何强制执行一个RelativeLayout的循环引用? [英] How do I enforce a circular reference in a RelativeLayout?

查看:197
本文介绍了我如何强制执行一个RelativeLayout的循环引用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个必须相互引用一个RelativeLayout的中两个小部件。从技术上讲它不是因为小部件循环引用垂直部件B和部件乙对准水平与插件答:以下对齐是我的code(浓缩):

I have two widgets within a RelativeLayout that must reference each other. Technically it is not a circular reference since the widget A is vertically aligned with widget B and widget B is horizontally aligned with widget A. Here is my code (condensed):

    <Button android:id="@+id/btnLanguageFrom"
        android:layout_width="wrap_content" 
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_alignParentLeft="true"
            android:layout_toLeftOf="@id/imgArrow"
            android:text="English" />

    <ImageView android:id="@+id/imgArrow"
        android:layout_width="wrap_content" 
            android:layout_height="wrap_content"
            android:layout_marginRight="10dp" 
            android:layout_alignParentTop="true"
            android:layout_alignBottom="@id/btnLanguageFrom"
            android:layout_centerHorizontal="true"
            android:src="@drawable/arrow_right" />

然而,当我建立我得到这个错误:

However when I build I get this error:

错误:没有资源的发现,   匹配给定的名称(在   layout_toLeftOf,值为   @ ID / imgArrow)。

Error: No resource found that matches the given name (at 'layout_toLeftOf' with value '@id/imgArrow').

有趣的是,Eclipse中的图形布局视图中正确显示它并没有抱怨的循环引用。

Interestingly, the Graphical Layout view in Eclipse displays it correctly and doesn't complain about the circular reference.

我看不出有两个部件引用彼此沿着不同的维度(水平和垂直)的问题,因为它不能导致无限循环。有没有解决这个问题,什么办法?这是我所知道的获得我需要的布局的唯一途径。

I don't see the problem with two widgets referencing each other along different dimensions (horizontal and vertical) since it cannot cause an infinite loop. Is there any way around this problem? This is the only way I know to get the layout I need.

在此先感谢, 巴里 附:有没有什么办法来声明一个id提前,像C / C ++?

Thanks in advance, Barry P.S. Is there any way to declare an id in advance, like in C/C++?

推荐答案

第一次引用一个ID,使用@ + preFIX,它告诉资源建设者添加ID,而不是试图找到它。因此,尝试:

The first time you reference an ID, use the @+ prefix, which tells the resource builder to add the ID, rather than trying to find it. So try:

android:layout_toLeftOf="@+id/imgArrow"

这篇关于我如何强制执行一个RelativeLayout的循环引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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