阅读更多 开发过Android应用的同学们都知道,Android工程-res- layout资源文件夹下存放着控制view布局的xml文件,我们可以通过 getViewById(int i)方法,从XML中构造view及其子类,在这个过程当中,XML文件中的一切layout属性也将被赋予这个view。当然,我们也能够通过代码来为某一个view来设置layout,那是后话。通过对集中layout的分析和比较我发现,Android中AbsoluteLayout与CSS的绝对定位很像,TableLayout与HTML的表格定位很像,而RelativeLayout与CSS的相对定位很像。前两者都已经是老生常谈了,我重点比较一下最后一对,即RelativeLayout与CSS的相对定位(Position:relative)。先看一段XML:
<?xml version="1.0" encoding="utf-8"?>
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:orientation="vertical">
            android:layout_width="fill_parent" android:layout_height="167px"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical">
                    android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:text="@string/Queen">
       

                    android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:text="@string/Rook">
       

                    android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:text="@string/Knight">
       

                    android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:text="@string/Bishop">