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里面使用滚动圈,privateViewprogressBarView;
在onCreate方法里写progressBarView=findViewById(R.id.ProgessBar_layout);
progressBarView.setVisibility(View.VISIBLE);
最后在获取完数据之后把滚动圈隐藏,
publicvoidhandleMessage(Messagemsg){
//TODOAuto-generatedmethodstub
switch(msg.what){
caseDATA_SUCCESS:
listViewAdater.notifyDataSetChanged();
progressBarView.setVisibility(View.INVISIBLE);