Reputation: 36654
I try to include xml_layoutA
into xml_layoutB
.
At first I didn't know i have to add <merge>
tag in xml_layoutA
.
but then I added this tag and then the xml_layoutA
started being aligned to left instead of to the right as before.
What has caused this change?
xml_layoutA.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tooltip_layout"
android:layout_width="262dp"
android:layout_height="92dp"
android:background="@drawable/tip_tool_top_right"
android:orientation="horizontal"
android:paddingTop="10dp"
android:paddingBottom="15dp"
android:paddingLeft="5dp"
android:paddingRight="10dp" >
<LinearLayout
...
</LinearLayout>
</LinearLayout>
vs.
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:id="@+id/tooltip_layout"
android:layout_width="262dp"
android:layout_height="92dp"
android:background="@drawable/tip_tool_top_right"
android:orientation="horizontal"
android:paddingTop="10dp"
android:paddingBottom="15dp"
android:paddingLeft="5dp"
android:paddingRight="10dp" >
<LinearLayout
...
</LinearLayout>
</LinearLayout>
</merge>
both case in same xml_layoutB.xml
in RelativeLayout
:
<include
android:id="@+id/tooltipFriends"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/friendsonline_bar"
android:layout_alignParentRight="true"
android:visibility="visible"
layout="@layout/tooltip_friends" />
Upvotes: 5
Views: 581
Reputation: 534
The problem you're facing is caused because those include
's parameters are ignored when using the merge
tag.
Anyway the merge
tag you have there is not needed and it's not doing much for you there. Basically the merge
tag is useful when you have more view and you want those views to be included in unknown layout. For example, you have those 4 tags you want to be reused
<merge>
<TextView ... />
<TextView ... />
<EditText ... />
<Button ... />
</merge>
Then when you use this:
<RelativeLayout>
<include layout="^^" />
</RelativeLayout>
What you'll get is this:
<RelativeLayout>
<TextView ... />
<TextView ... />
<EditText ... />
<Button ... />
</RelativeLayout>
Any parameters on the original include
tag will be discarded, because there is no way to tell to which tag they should be added.
Upvotes: 1