我有一个按钮
问题是:我有一个Activity中有一个按钮
以下是xml文件: special_button.xml
A
,在special_button.xml
中,我在所有的Activity中重复使用它。每个Activity都有一个根RelativeLayout
。问题是:我有一个Activity中有一个按钮
B
和A
在同一位置,我想将B
移到A
上面,但我无法从Activity的xml文件中引用A
。以下是xml文件: special_button.xml
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android" >
<Button
android:id="@+id/A"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="15dp"
android:layout_marginRight="20dp"/>
</merge>
layout_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<include layout="@layout/special_button" />
<Button
android:id="@+id/B"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_above="<id to reference button A>"
android:layout_marginBottom="15dp"
android:layout_marginRight="20dp" />
</RelativeLayout>
merge
标签,实际上是活动的RelativeLayout
。我仍然无法访问按钮A。 - aysonje<include>
一个与RelativeLayout
的ID不同的ID。请检查我的修改并查看是否有帮助。 - anddev84A
。只是想让你知道,我没有向<include>
标签添加任何数据,只是简单地写了<include layout="@layout/special_button" />
,它就起作用了。 - aysonje