`
xiaoming123123
  • 浏览: 98706 次
  • 性别: Icon_minigender_1
  • 来自: 南昌
社区版块
存档分类
最新评论

ProgressBar的使用(注意小细节)

 
阅读更多
做项目的时候希望滚动圈出现在中间,在布局文件中,如果使用的线性布局,那么滚动圈出现在左上角,所以应该把LinearLayout改为RelativeLayout:

main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:layout_width="fill_parent" android:layout_height="fill_parent"
	android:background="@color/white"
	>
	<include android:id="@+id/title" layout="@layout/main_title"/>
	<GridView android:id="@+id/gridview" android:layout_width="wrap_content"
		android:layout_height="wrap_content" android:numColumns="3"
		android:verticalSpacing="2dip" android:horizontalSpacing="2dip"
		  android:scrollbars="none"
		android:gravity="center">
	</GridView>
	 <include android:layout_centerHorizontal="true"
		android:layout_centerInParent="true" android:layout_width="wrap_content"
		android:visibility="gone" android:layout_height="90dip" layout="@layout/progressbar" />
</RelativeLayout>


include包含外部的progressbar.xml布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
  	xmlns:android="http://schemas.android.com/apk/res/android"
  	android:id="@+id/ProgessBar_layout"
  	android:layout_width="wrap_content"
  	android:layout_height="wrap_content"
  	android:focusable="false" 
  	android:padding="5px" 
  	android:background="@drawable/progress_back">
  	<ProgressBar android:id="@+id/ProgressBar_bar"
		style="?android:attr/progressBarStyle" android:layout_height="wrap_content"
		android:layout_width="wrap_content" android:indeterminateDrawable="@drawable/draw_progessbar"
		android:layout_centerHorizontal="true" 
		android:layout_alignParentTop="true"
		android:layout_marginTop="3dip"
		android:layout_marginBottom="3dip"
		/>
  	<TextView android:id="@+id/ProgressBar_txt" android:layout_width="wrap_content"
		android:layout_height="wrap_content" 
		android:textColor="@color/white"
		android:text="正在加载中,请稍候..."
		android:lines="2"
		android:layout_marginTop="3dip"
		android:layout_marginBottom="3dip"
		android:layout_below="@id/ProgressBar_bar"/>

</RelativeLayout>



在Activity里面使用滚动圈,private View progressBarView;
在onCreate方法里写progressBarView = findViewById(R.id.ProgessBar_layout);
                  progressBarView.setVisibility(View.VISIBLE);

最后在获取完数据之后把滚动圈隐藏,
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
switch (msg.what) {
case DATA_SUCCESS:
listViewAdater.notifyDataSetChanged();
progressBarView.setVisibility(View.INVISIBLE);
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics