Using “merge” and “include”

2019-07-11 02:46发布

问题:

I'm trying to put a copyright image in the bottom of my LinearLayout with an "include tag". I am doing it successfully, but when I'm trying to add android:layout_marginTop="330dp" or android:layout_marginBottom="20dp" for instance to my include - it doesn't show in the UI. What is the problem ?

Here is my code: copyrights.xml:

 <merge xmlns:android="http://schemas.android.com/apk/res/android">
    <ImageView
            android:src="@drawable/copyrights"
            android:id="@+id/copyrights"
            android:layout_width="fill_parent"
            android:layout_height="40dip"/>
</merge>

mylayout.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:padding="10dip"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">  
        <include layout="@layout/copyrights"  android:layout_marginTop="330dp"/>
    </LinearLayout>  

回答1:

The <include /> tag is basically a copy&paste instruction for the android layout framework. It's not an actual object in your layout hierachy. That means that it can't have margin/padding/size/any other layout property.

Assign the margin to the <ImageView /> in your layout instead.