理解android:layout_centerInParent="true"
的有关信息介绍如下:android:layout_centerInParent="true"这句话定义为将控件置于父控件的中心位置还是不知道什么意思,在这里我来一次咬文嚼字
关键词
控件
父控件
理解这两个概念就好办
我们看这段代码
android:layout_width="match_parent" android:layout_height="match_parent" > android:id="@+id/imageButton0" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:src="@drawable/help" > android:id="@+id/imageButton1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/imageButton0" android:src="@drawable/c1" >
去掉之前android:layout_centerInParent="true",
我们跑一下
android:layout_width="match_parent" android:layout_height="match_parent" > android:id="@+id/imageButton0" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/help" > android:id="@+id/imageButton1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/imageButton0" android:src="@drawable/c1" >
这个程序
会看到我左边图片样子
帮助按钮会在古天乐(c1)的上方
然后我们加上代码android:layout_centerInParent="true"
这时我们会发现
图片都去中央去了
这说明这个属性有居中的功能但我们还是不能理解父控件是谁
是古天乐图片控件
还是相对布局
这时我们把古天乐控件去掉
我们在看效果:
android:layout_width="match_parent" android:layout_height="match_parent" > android:id="@+id/imageButton0" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/help" >
我们会发现依然在原来的位置上没变,这说明是相对整个布局而居中的
这个·父控件就是RelativeLayout