Android中Market的Loading效果实现方法
作者:白羽雕弓 时间:2023-11-16 09:37:33
本文实例讲述了Android中Market的Loading效果实现方法。分享给大家供大家参考。具体如下:
在Android中,要实现Loading效果,一般情况下都使用ProgressDialog控件。ApiDemos/src/com/example/android/apis/view/ProgressBar3.java 提供两个demo:
仔细看了Android Market,发现却是不一样的,请看截图:
那到底如何实现呢?首先,我们创建一个布局文件,
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
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Java持久化框架Hibernate与Mybatis优劣及选择详解
2023-12-03 19:46:14
解决Android手机屏幕横竖屏切换
2022-10-21 18:55:33
![](https://img.aspxhome.com/file/2023/4/104644_0s.png)
Java 反转带头结点的单链表并显示输出的实现过程
2022-06-08 18:34:39
![](https://img.aspxhome.com/file/2023/0/110610_0s.jpg)
Android使用SlidingPaneLayout 实现仿微信的滑动返回
2023-08-29 04:48:21
![](https://img.aspxhome.com/file/2023/7/123337_0s.gif)
SpringBoot中使用Filter和Interceptor的示例代码
2022-06-28 17:20:04
![](https://img.aspxhome.com/file/2023/6/76496_0s.jpg)
浅谈android Fragment横竖屏翻转对重新加载的要求
2023-07-27 21:55:28
spring retry实现方法请求重试的使用步骤
2021-12-31 15:11:11
Android中Snackbar的使用方法及小技巧
2023-10-30 03:13:31
![](https://img.aspxhome.com/file/2023/8/103888_0s.gif)
C# API中模型与它们的接口设计详解
2023-11-03 19:49:01
C# 如何调用SAP RFC
2023-07-02 18:11:42
![](https://img.aspxhome.com/file/2023/7/70437_0s.png)
Java中synchronized的几种使用方法
2023-06-19 16:33:28
![](https://img.aspxhome.com/file/2023/8/62228_0s.webp)
WinForm相对路径的陷阱
2022-01-20 10:25:18
Mybatis-Plus的使用详解
2022-01-18 18:39:27
![](https://img.aspxhome.com/file/2023/1/61801_0s.jpg)
C#实现的微信网页授权操作逻辑封装示例
2022-08-31 04:30:05
IDEA新建springboot项目时未生成pom.xml文件的解决操作
2022-08-22 03:16:31
![](https://img.aspxhome.com/file/2023/8/62518_0s.png)
c# 获得局域网主机列表实例
2022-07-12 21:46:58
如何把spring boot项目部署到tomcat容器中
2023-10-08 18:53:51
利用Java计算某个日期是星期几
2023-11-17 05:49:42
很棒的Android弹幕效果实例
2022-07-30 17:41:40
![](https://img.aspxhome.com/file/2023/7/137677_0s.jpg)
C#异常执行重试的实现方法
2023-12-04 16:24:59