- 每个ViewGroup类都会实现一个扩展ViewGroup.LayoutParams的嵌套类。此子类包含的属性类型会根据需要为视图组的每个子视图定义尺寸和位置。
- 子视图的在父视图中的位置信息可以调用以下函数获得
Merge标签
这个标签通常是作为一个xml文件的根标签,重复布局的时候需要用到,算是一种布局优化。
它的作用是将包含的所有控件都添加到上层布局中,比如说:
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="center"
android:src="@drawable/golden_gate" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dip"
android:layout_gravity="center_horizontal|bottom"
android:padding="12dip"
android:background="#AA000000"
android:textColor="#ffffffff"
android:text="Golden Gate" />
</merge>
我们所写的布局文件都是加载在Android系统提供的一个Fragment中,所以上面Merge标签中的ImageView和TextView会直接加载到上层Fragment中。这样写的好处是什么呢?
你看,如果我们用LinearLayout包裹这两个控件,并将这个xml通过include加载到另外一个LinearLayout布局中,是不是相当于在LinearLayout中又嵌套了一个LinearLayout,这样做的话会很影响性能。但是如果使用Merge标签的话,这个问题就不会发生了。
但是这样又会有一个问题,如果我们想要include的布局是horizontal的LinearLayout时呢?