Android中Market的Loading效果实现方法

时间:2021-10-17 07:07:45

本文实例讲述了android中market的loading效果实现方法。分享给大家供大家参考。具体如下:

在android中,要实现loading效果,一般情况下都使用progressdialog控件。apidemos/src/com/example/android/apis/view/progressbar3.java 提供两个demo:

Android中Market的Loading效果实现方法

Android中Market的Loading效果实现方法

仔细看了android market,发现却是不一样的,请看截图:

Android中Market的Loading效果实现方法

那到底如何实现呢?首先,我们创建一个布局文件,
res/layout/fullscreen_loading_indicator.xml, 其内容如下:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?xml version="1.0" encoding="utf-8"?>
<linearlayout
 xmlns:android="http://schemas.android.com/apk/res/android"
   android:gravity="center_vertical|center_horizontal"
  android:orientation="horizontal"
  android:id="@+id/fullscreen_loading_style"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
 >
 <progressbar
 android:layout_gravity="center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="?android:attr/progressbarstylesmall"
/>
<textview
  android:id="@+id/current_action"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_marginleft="5.0dip"
  android:text="@+string/loading"
/>
</linearlayout>

然后在main.xml 把它include 进来

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?xml version="1.0" encoding="utf-8"?>
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical" android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  <linearlayout android:orientation="vertical"
    android:id="@+id/main_info"
    android:visibility="gone"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <textview android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:text="abc"></textview>
  </linearlayout>
  <linearlayout android:orientation="vertical"
    android:id="@+id/main_loading"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <include android:visibility="visible"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      layout="@layout/fullscreen_loading_style" />
  </linearlayout>
</linearlayout>

主程序:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package com.tymx.fullloading;
import android.app.activity;
import android.os.bundle;
import android.os.handler;
import android.os.message;
import android.view.view;
import android.widget.linearlayout;
public class myfullloading extends activity {
  /** called when the activity is first created. */
  private linearlayout mloadinglayout;
  @override
  public void oncreate(bundle savedinstancestate) {
    super.oncreate(savedinstancestate);
    setcontentview(r.layout.main);
    final handler handler = new handler(){
      @override
      public void handlemessage(message msg) {
        // todo auto-generated method stub
        super.handlemessage(msg);
        if (msg.what==1){
          mloadinglayout = (linearlayout)findviewbyid(r.id.fullscreen_loading_style);
          mloadinglayout.setvisibility(view.gone);
          linearlayout mmain = (linearlayout)findviewbyid(r.id.main_info);
          mmain.setvisibility(view.visible);
        }
      }
    };
    new thread(){
      public void run(){
        for (int i=0;i<1000;i++){
          system.out.print(i+"");
        }
        message msg = handler.obtainmessage(1,"flash");
        handler.sendmessage(msg);
      }
    }.start();
  }
}

运行的效果为:

Android中Market的Loading效果实现方法

希望本文所述对大家的android程序设计有所帮助。