Android布局中的include

最近学习了android的布局样式标签,布局样式标签一共有5个,感觉FrameLayout和RelativeLayout最为灵活,而FrameLayout就像web中iframe框架一样,是一个框架布局样式,可以用include标签载入定义的另一个layout文件,现在用一个ProgressBar的例子学习一下 FrameLayout。(文/huangbq

首先,我们创建一个布局文件,res/layout/fullscreen_loading.xml, 其内容如下:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout
  3.     xmlns:android="http://schemas.android.com/apk/res/android"
  4.     android:orientation="horizontal"
  5.     android:gravity="center_vertical|center_horizontal"
  6.     android:layout_width="fill_parent"
  7.     android:layout_height="fill_parent  
  8.     android:id="@+id/fullscreen_loading"
  9.     android:visibility="gone"
  10.     >
  11.     <ProgressBar
  12.         android:layout_gravity="center_vertical"
  13.         android:layout_width="wrap_content"
  14.         android:layout_height="wrap_content"
  15.         style="?android:attr/progressBarStyleSmall"
  16.         >
  17.     </ProgressBar>
  18.     <TextView
  19.         android:layout_width="wrap_content"
  20.         android:layout_height="wrap_content"
  21.         android:layout_marginLeft="5.0dip"
  22.         android:text="loading..."
  23.         >
  24.     </TextView>
  25. </LinearLayout>
然后在main.xml 把它include 进来
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <FrameLayout
  3.     xmlns:android="http://schemas.android.com/apk/res/android"
  4.     android:layout_width="fill_parent"
  5.     android:layout_height="fill_parent"
  6.     >
  7.     <LinearLayout
  8.         android:orientation="vertical"
  9.         android:visibility="gone"
  10.         android:layout_width="fill_parent"
  11.         android:layout_height="fill_parent"
  12.         >
  13.     </LinearLayout>
  14.     <include
  15.         android:visibility="visible"
  16.         android:layout_width="fill_parent"
  17.         android:layout_height="fill_parent"
  18.         layout="@layout/fullscreen_loading"
  19.         >
  20.     </include>
  21. </FrameLayout>

主程序 LoadingActivity.java:
  1. package com.google.android.test;
  2. import android.app.Activity;
  3. import android.os.Bundle;
  4. import android.widget.LinearLayout;
  5. public class LoadingActivity extends Activity {
  6.     /** Called when the activity is first created. */
  7.     @Override
  8.     public void onCreate(Bundle savedInstanceState) {
  9.         super.onCreate(savedInstanceState);
  10.         setContentView(R.layout.main);
  11.     }
  12. }

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值