include和merge的问题

include和merge的问题


发现一个问题

merge文件

<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    >

            <ImageView
                android:id="@+id/theme_toolbar_activity_img_sigle_selected"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/theme_toolbar_activity_selected"
                android:visibility="gone" />

        <TextView
            android:id="@+id/theme_toolbar_activity_txt_sigle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="@string/theme_layout_single_toolbar"
            android:textColor="@color/theme_toolbar_activity_txt_default"
            android:textSize="@dimen/dp_12" />

</merge>


然后 我引用
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/theme_layout_root"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    android:paddingLeft="@dimen/dp_20"
    android:paddingRight="@dimen/dp_20"
    android:paddingBottom="@dimen/dp_20"
    android:paddingTop="@dimen/dp_10"
    >
		<include
	        layout="@layout/theme_toolbar_activity_include"
	        android:layout_width="wrap_content"
	        android:layout_height="wrap_content"
	        android:layout_alignParentTop="true" 
	        />
</RelativeLayout>




这个时候 padding就不起作用了 即使我在代码手动设置padding也是不起作用的 并且 即使我把merge给位RelativeLayout,依然是这样 不过这个时候 我在include上面 设置margin就好使了 但是 还是有一个多余的节点。

但是 我在另一个xml里面 引入merge就可以,对比了一下 唯一的区别 就是 这个父view是根节点,所以 我把上面的修改了一下

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/theme_layout_root"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    android:fitsSystemWindows="true" 
    >
	<RelativeLayout
	    android:layout_width="match_parent"
	    android:layout_height="match_parent"
	    android:paddingLeft="@dimen/dp_20"
		android:paddingRight="@dimen/dp_20"
		android:paddingBottom="@dimen/dp_20"
		android:paddingTop="@dimen/dp_10"
	    >
		<include
	        layout="@layout/theme_toolbar_activity_include"
	        android:layout_width="wrap_content"
	        android:layout_height="wrap_content"
	        android:layout_alignParentTop="true" 
	        />
	</RelativeLayout>
</RelativeLayout>



呃...好了  ̄□ ̄||

猜你喜欢

转载自trylovecatch.iteye.com/blog/2252521