网上关于gravity与layout_gravity的分析很多,这里不过多描述,有意者可参考 http://blog.csdn.net/feng88724/article/details/6333809
在实际使用中发现,虽然我们知道gravity与layout_gravity的用法,但我们不能很好的设置好他,尤其是布局中包含多个子控件的时候。这里做几点总结:
一、父控件布局设置android:layout_width和android:layout_height为match_parent;
二、父控件布局设置android:gravity来控制子控件的位置;之所以不通过子控件设置android:layout_gravity控制,是因为某些情况下这种设置不起作用,比如父控件为linearlayout并且设置成android:orientation="horizontal" 时;
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/bg_