适用范围:listview显示的项目为耗时的加载操作
如:获取系统安装程序,从服务器上下载并显示消息或内容
1.定义布局文件
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<!--
android:cacheColorHint="#00000000" 缓存的颜色 默认是黄色
android:divider="#00ffffff" 分割线
android:dividerHeight="3.0dip" 分割线的宽度
-->
<ListView
android:id="@+id/lv_appmanage"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:cacheColorHint="#00000000"
android:divider="#fff"
android:fastScrollEnabled="true"
android:dividerHeight="1.0dip"
android:paddingLeft="3.0dip"
android:paddingRight="3.0dip" />
<RelativeLayout
android:id="@+id/rl_loading"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_centerInParent="true">
<ProgressBar
android:id="@+id/pb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:text="正在加载应用程序。。"
android:textColor="#fff"
android:textSize="22sp" />
</LinearLayout>
</RelativeLayout>
</FrameLayout>
2.activity中控制隐藏或显示
//找到相应的布局组件
RelativeLayout rl_loading = (RelativeLayout) findViewById(R.id.rl_loading);
//设置相应的显示状况
//View.VISIBLE (控件显示)View.INVISIBLE(控件隐藏 但占据空间)
//View.GONE(控件隐藏 不占据空间)
rl_loading.setVisibility(View.GONE);