Android随手记

android:layout_centerInParent=”true“

只要你容器是RelativeLayout的时候才有。此时设置为RelativeLayout里的子控件属性为android:layout_centerInParent=”true“,就是水平垂直都居中。
在xml布局中如下:
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
<TextView
android:text="欢迎注册"
android:gravity="center"
android:textSize="15pt"
android:textColor="#ff8c00"
android:layout_centerInParent=”true“
android:layout_width="fill_parent"
android:layout_height="wrap_content"
></TextView>

</RelativeLayout >

android:gravity="center_horizontal" 与 android:layout_gravity="center_horizontal" 有什么区别吗??

凡是有layout_的都是告诉父级要素怎布局自己,我这么说有点绕口令的感觉,我就打个比方吧。有个大盒子里面有个中盒子,中盒子里面有个小盒子,现在中盒子定义了
android:layout_gravity="center_horizontal"属性意思是给大盒子说“老大请把我安排在你里面的水平剧中位置吧”;中盒子又定义了android:gravity="center_horizontal" 意思是中盒子给小盒子说“老弟你到我里面的水平剧中位置来”

猜你喜欢

转载自blog.csdn.net/weixin_40213204/article/details/86549722