include标签内有一些属性,layout内也可以有一些属性
像<include layout="@layout/aa" />这种形式的include标签,layout内所有属性都有效。
但是如果想要用include内的属性,必须重新宽高,比如
<include layout="@layout/aa"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
如果没有重写宽高,android:layout_alignParentRight="true"是无效的,但是写了宽高的话,layout内的layout属性都会失效(比如 android:layout_alignParentRight,android:layout_centerVertical都会失效),但是非layout属性依然有效比如gravity,background
简单说就说, include写了宽高,用include内的属性,layout内的layout相关属性失效
include没写宽高,用layout内的属性
像<include layout="@layout/aa" />这种形式的include标签,layout内所有属性都有效。
但是如果想要用include内的属性,必须重新宽高,比如
<include layout="@layout/aa"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
如果没有重写宽高,android:layout_alignParentRight="true"是无效的,但是写了宽高的话,layout内的layout属性都会失效(比如 android:layout_alignParentRight,android:layout_centerVertical都会失效),但是非layout属性依然有效比如gravity,background
简单说就说, include写了宽高,用include内的属性,layout内的layout相关属性失效
include没写宽高,用layout内的属性
demo
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<include layout="@layout/aa" />
</RelativeLayout>
aa.xml
<?xml version="1.0" encoding="utf-8"?><!--完成按钮,带绿圆为背景的数字-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:gravity="right|center_vertical"
android:orientation="horizontal">
<TextView
android:background="#ff0000"
android:id="@+id/picker_image_preview_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:enabled="true"
android:gravity="center"
android:text="第一" />
<TextView
android:layout_marginLeft="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="你好" />
</LinearLayout>