Android中Market的Loading效果實現方法
本文實例講述了Android中Market的Loading效果實現方法。分享給大家供大家參考。具體如下:
在Android中,要實現Loading效果,一般情況下都使用ProgressDialog控件。ApiDemos/src/com/example/android/apis/view/ProgressBar3.java 提供兩個demo:


仔細看了Android Market,發(fā)現卻是不一樣的,請看截圖:

那到底如何實現呢?首先,我們創(chuàng)建一個布局文件,
res/layout/fullscreen_loading_indicator.xml, 其內容如下:
<?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 進來
<?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>
主程序:
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程序設計有所幫助。
- 三款Android炫酷Loading動畫組件推薦
- 一看就喜歡的loading動畫效果Android分析實現
- Android自定義加載loading view動畫組件
- Android項目實戰(zhàn)手把手教你畫圓形水波紋loadingview
- Android實現創(chuàng)意LoadingView動畫效果
- Android自定義View實現loading動畫加載效果
- Android Studio卡很久(loading)的問題解決辦法
- Android 自定義通用的loadingview實現代碼
- Android自定義環(huán)形LoadingView效果
- Android實現一個帶粘連效果的LoadingBar
相關文章
Android中ScrollView嵌套GridView顯示不全解決方法
這篇文章主要介紹了Android中ScrollView嵌套GridView顯示不全解決方法的相關資料,需要的朋友可以參考下2017-04-04
Android Studio導入Eclipse項目的兩種方法
本文主要介紹了Android Studio導入Eclipse項目的兩種方法。具有一定的參考價值,下面跟著小編一起來看下吧2017-01-01
android基礎總結篇之八:創(chuàng)建及調用自己的ContentProvider
這篇文章主要介紹了android基礎總結篇之八:創(chuàng)建及調用自己的ContentProvider,有興趣的可以了解一下。2016-11-11
Android中Android Virtual Device(AVD)使用教程
這篇文章主要介紹了Android中Android Virtual Device(AVD)使用教程,本文還對使用過程中發(fā)生的一些錯誤給出了處理方法,需要的朋友可以參考下2015-01-01

