LinearLayout and FrameLayout

LinearLayout and FrameLayout

  • LinearLayout 单层线性布局,子控件不可覆盖,而以垂直或水平布局。

  • FrameLayout 单帧空间垂直布局,display a singer item,but you can populate it with many items, setting one to visible while the others are invisible.只有一个子控件可见,其它均被隐藏。每个添加的子控件都被放在布局的左上角,并覆盖前一子控件的上层。


LinearLayout 做出如下效果:
LinearLayout and FrameLayout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="160px"
    android:background="@android:color/white"
    >
   <TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"
    />
    
    <com.studio.android.Chessboard android:id="@+id/snake" android:layout_width="match_parent"
		android:layout_height="match_parent" tileSize="24"/>   
          <LinearLayout 
         xmlns:android="http://schemas.android.com/apk/res/android"
         android:orientation="horizontal"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
          android:background="@android:color/black"
          >
    </LinearLayout>
</LinearLayout>


分析:The first LinearLayout 垂直布局,所以TextView and Chessboard 垂直分布。第二个LinearLayout则位于其下。也就是两个LinearLayout不相互重叠,依次排列。

FrameLayout的布局:
LinearLayout and FrameLayout
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/bg"
    >
	<RelativeLayout
		android:layout_width="match_parent"
		android:layout_height="match_parent">
		<TextView
			android:id="@+id/text"
			android:text="@string/hello"
			android:visibility="visible"
			android:layout_width="wrap_content"
			android:layout_height="wrap_content"
			android:layout_centerHorizontal="true"
			android:layout_centerVertical="true"
			android:textColor="#ff0000"
			android:textSize="24sp"
			/>
	</RelativeLayout>
<Button
   android:layout_width="50px"
   android:layout_height="wrap_content"
   android:text="确定"
   />
</FrameLayout>

分析:在整个的FrameLayout的布局中,上层子控件覆盖下层子控件,每个子控件都被放在左上角(0,0)位置。

你可能感兴趣的:(xml)