RelativeLayout-在另一个嵌套视图中引用ID-这可能吗? [英] RelativeLayout - referencing ids within another nested view - is this possible?

查看:81
本文介绍了RelativeLayout-在另一个嵌套视图中引用ID-这可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在TV2相对于TV1,TV1和TV2在布局的不同分支内的情况下,是否可以做这样的事情?

Is it possible to do something like this where TV2 is relative to TV1, where TV1 and TV2 are within different branches of the layout?

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <RelativeLayout
        android:id="@+id/RV1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <TextView
            android:id="@+id/TV01"
            android:layout_width="wrap_content"
            android:layout_height="50dp"
            android:text="test text" />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/RV2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/RV1" >

        <TextView
            android:id="@+id/TV02"
            android:layout_width="wrap_content"
            android:layout_height="50dp"
            android:layout_toRightOf="@+id/TV01"  <--------- this references TV01 within the top RelativeView !!!
            android:text="other text" />
    </RelativeLayout>

</RelativeLayout>

在此示例中,

语句android:layout_toRightOf="@+id/TV01"似乎不起作用,因为TV01TV02不在另一个RealtiveLayout分支中.

in this example the statement android:layout_toRightOf="@+id/TV01" does not seem to work, since TV01 is within another RealtiveLayout branch than TV02.

是否可以通过某种方式进行这样的引用?

非常感谢!

推荐答案

否,您不能使用RelativeLayout定位.但是:

No, you cannot use RelativeLayout positioning like that. However:

  • 您可以结合使用RV1RV2

  • 您可以将RV2放置在RV1
  • 的右侧
  • You can position RV2 to the right of RV1

这篇关于RelativeLayout-在另一个嵌套视图中引用ID-这可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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