我需要访问包含在另一个b.xml布局中的x.xml布局中的视图。 例如, 这是A.XML访问包含的xml布局视图
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button
android:id="@+id/xyz"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="XYZ" />
</RelativeLayout>
而且,在B.XML
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<include
android:id="@+id/a_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
layout="@layout/a" />
<TextView
android:id="@+id/label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/xyz"
android:text="Show me below xyz" />
</RelativeLayout>
我必须这样做,在XML代码,因为如果我在Java中做到这一点就必须经过setContentView()然后设置TextView'label'的LayoutParams不会生效。
我想,每个人都明白我想问什么。等待好的回复。
谢谢大家。
右边的图片是我想要实现的,剩下的就是我用当前的代码得到的。
您想问什么? – 2012-04-10 07:48:32
如果我已经猜到了,那么通过它的id来访问它:'findViewById(R.id.label)' – 2012-04-10 07:50:03
你说得对,我可以使用findViewById(R.id.label)来访问它。但我不能这样做android:layout_below =“@ id/xyz” – 2012-04-10 07:59:09