【发布时间】:2014-02-03 08:36:56
【问题描述】:
我在special_button.xml 内部有一个按钮A,我可以在所有活动中重复使用该按钮。每个活动都有一个根RelativeLayout。
问题:我的一个活动有一个按钮,B,与A 位于同一位置。我决定将B 移到A 上方,但我无法从活动的xml 中引用A。
这里是xmls
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>
【问题讨论】: