在RelativeLayout中使用<include>

mic*_*ael 1 android android-layout

我有一个有一个孩子的RelativeLayout<include another.xml>

像这样root.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/root"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
     android:orientation="horizontal">
<include layout="@layout/another.xml"/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

我的问题是Android是否尊重android:layout_alignParentRight="true"我的顶级水平another.xml

another.xml是这样的:

<RelativelLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/control_panel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:orientation="vertical">
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

基本上,我希望我的所有观点都another.xml与我的根本正确对齐.我上面已经尝试过了,但是我的视图another.xml与我的根保持一致.

谢谢.

Win*_*tet 5

不,你必须做这样的事情,而Orientation仅适用于LinearLayout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/root"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >


    <RelativelLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true" >
    <include layout="@layout/another.xml" />
    </RelativelLayout>

</RelativeLayout><RelativeLayout>

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)