首页 > 系统 > Android > 正文

Android中Market的Loading效果实现方法

2019-10-24 20:35:43
字体:
来源:转载
供稿:网友

这篇文章主要介绍了Android中Market的Loading效果实现方法,较为详细的分析了Android中loading效果的相关布局及功能实现技巧,具有一定参考借鉴价值,需要的朋友可以参考下

本文实例讲述了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. <?xml version="1.0" encoding="utf-8"?> 
  2. <LinearLayout 
  3. xmlns:android="http://schemas.android.com/apk/res/android" 
  4. android:gravity="center_vertical|center_horizontal" 
  5. android:orientation="horizontal" 
  6. android:id="@+id/fullscreen_loading_style" 
  7. android:layout_width="fill_parent" 
  8. android:layout_height="fill_parent" 
  9. <ProgressBar 
  10. android:layout_gravity="center_vertical" 
  11. android:layout_width="wrap_content" 
  12. android:layout_height="wrap_content" 
  13. style="?android:attr/progressBarStyleSmall" 
  14. /> 
  15. <TextView 
  16. android:id="@+id/current_action" 
  17. android:layout_width="wrap_content" 
  18. android:layout_height="wrap_content" 
  19. android:layout_marginLeft="5.0dip" 
  20. android:text="@+string/loading" 
  21. /> 
  22. </LinearLayout> 

然后在main.xml 把它include 进来

 

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

主程序:

 

 
  1. package com.tymx.fullloading; 
  2. import android.app.Activity; 
  3. import android.os.Bundle; 
  4. import android.os.Handler; 
  5. import android.os.Message; 
  6. import android.view.View; 
  7. import android.widget.LinearLayout; 
  8. public class myFullLoading extends Activity { 
  9. /** Called when the activity is first created. */ 
  10. private LinearLayout mLoadingLayout; 
  11. @Override 
  12. public void onCreate(Bundle savedInstanceState) { 
  13. super.onCreate(savedInstanceState); 
  14. setContentView(R.layout.main); 
  15. final Handler handler = new Handler(){ 
  16. @Override 
  17. public void handleMessage(Message msg) { 
  18. // TODO Auto-generated method stub 
  19. super.handleMessage(msg); 
  20. if (msg.what==1){ 
  21. mLoadingLayout = (LinearLayout)findViewById(R.id.fullscreen_loading_style); 
  22. mLoadingLayout.setVisibility(View.GONE); 
  23. LinearLayout mMain = (LinearLayout)findViewById(R.id.main_info); 
  24. mMain.setVisibility(View.VISIBLE); 
  25. }; 
  26. new Thread(){ 
  27. public void run(){ 
  28. for (int i=0;i<1000;i++){ 
  29. System.out.print(i+""); 
  30. Message msg = handler.obtainMessage(1,"flash"); 
  31. handler.sendMessage(msg); 
  32. }.start(); 

运行的效果为:

Android中Market的Loading效果实现方法

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

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表