最近学习了android的布局样式标签,布局样式标签一共有5个,感觉FrameLayout和RelativeLayout最为灵活,而FrameLayout就像web中iframe框架一样,是一个框架布局样式,可以用include标签载入定义的另一个layout文件,现在用一个ProgressBar的例子学习一下 FrameLayout。(文/huangbq)
首先,我们创建一个布局文件,res/layout/fullscreen_loading.xml, 其内容如下:
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="horizontal"
- android:gravity="center_vertical|center_horizontal"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent
- android:id="@+id/fullscreen_loading"
- android:visibility="gone"
- >
- <ProgressBar
- android:layout_gravity="center_vertical"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- style="?android:attr/progressBarStyleSmall"
- >
- </ProgressBar>
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginLeft="5.0dip"
- android:text="loading..."
- >
- </TextView>
- </LinearLayout>
- <?xml version="1.0" encoding="utf-8"?>
- <FrameLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- >
- <LinearLayout
- android:orientation="vertical"
- android:visibility="gone"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- >
- </LinearLayout>
- <include
- android:visibility="visible"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- layout="@layout/fullscreen_loading"
- >
- </include>
- </FrameLayout>
- package com.google.android.test;
- import android.app.Activity;
- import android.os.Bundle;
- import android.widget.LinearLayout;
- public class LoadingActivity extends Activity {
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- }
- }