iis服务器助手广告广告
返回顶部
首页 > 资讯 > 移动开发 >Android模拟美团客户端进度提示框
  • 810
分享到

Android模拟美团客户端进度提示框

客户端Android 2022-06-06 09:06:45 810人浏览 独家记忆
摘要

用过美团客户端的朋友都知道,美团的加载等待提示很有意思,是一种动画的形式展现给我们,下面我们就对这背后的原理进行了解,然后实现自己的等待动画效果。 首先我们准备两张图片: 这

用过美团客户端的朋友都知道,美团的加载等待提示很有意思,是一种动画的形式展现给我们,下面我们就对这背后的原理进行了解,然后实现自己的等待动画效果。
首先我们准备两张图片:

这两张图片看起来一模一样啊?细心的朋友会发现唯一不同的就在脚部,OK,我们就利用这两张图片的轮换播放实现动画效果,下面看一下代码:
1.动画文件frame_meituan.xml:


<?xml version="1.0" encoding="utf-8"?> 
<animation-list xmlns:Android="Http://schemas.android.com/apk/res/android" 
 android:oneshot="false" > 
 <item 
 android:drawable="@drawable/progress_loading_image_01" 
 android:duration="150"/> 
 <item 
 android:drawable="@drawable/progress_loading_image_02" 
 android:duration="150"/> 
</animation-list> 

150毫秒进行图片的切换,模拟动画效果。
2.简单自定义一个控件-MeituanProgressDialog.java:


package com.finddreams.runningman; 
import android.app.ProgressDialog; 
import android.content.Context; 
import android.graphics.drawable.AnimationDrawable; 
import android.os.Bundle; 
import android.widget.ImageView; 
import android.widget.TextView; 
import com.example.runningman.R; 
 
public class MeituanProgressDialog extends ProgressDialog { 
 private AnimationDrawable mAnimation; 
 private Context mContext; 
 private ImageView mImageView; 
 private String mLoadingTip; 
 private TextView mLoadingTv; 
 private int count = 0; 
 private String oldLoadingTip; 
 private int mResid; 
  
 public MeituanProgressDialog(Context context, String content, int id) { 
 super(context); 
 this.mContext = context; 
 this.mLoadingTip = content; 
 this.mResid = id; 
 setCanceledOnTouchOutside(true); 
 } 
 @Override 
 protected void onCreate(Bundle savedInstanceState) { 
 super.onCreate(savedInstanceState); 
 initView(); 
 initData(); 
 } 
 private void initData() { 
 mImageView.setBackgroundResource(mResid); 
 // 通过ImageView对象拿到背景显示的AnimationDrawable 
 mAnimation = (AnimationDrawable) mImageView.getBackground(); 
 mImageView.post(new Runnable() { 
 @Override 
 public void run() { 
 mAnimation.start(); 
 } 
 }); 
 mLoadingTv.setText(mLoadingTip); 
 } 
 public void setContent(String str) { 
 mLoadingTv.setText(str); 
 } 
 private void initView() { 
 setContentView(R.layout.progress_dialog);// 显示界面 
 mLoadingTv = (TextView) findViewById(R.id.loadingTv); 
 mImageView = (ImageView) findViewById(R.id.loadingIv); 
 } 
} 

上面用到的提示布局文件的progress_dialog.xml:


<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
 android:layout_width="wrap_content" 
 android:layout_height="wrap_content" 
 android:layout_gravity="center" 
 android:orientation="vertical" > 
 <ImageView 
 android:id="@+id/loadingIv" 
 android:layout_width="wrap_content" 
 android:layout_height="wrap_content" 
 android:background="@anim/frame_meituan"/> 
 <TextView 
 android:id="@+id/loadingTv" 
 android:layout_width="wrap_content" 
 android:layout_height="wrap_content" 
 android:layout_alignBottom="@+id/loadingIv" 
 android:layout_centerHorizontal="true" 
 android:textSize="20sp" 
 android:text="正在加载中.." /> 
</RelativeLayout> 

最后在Activity中调用:


package com.finddreams.runningman; 
import com.example.runningman.R; 
import android.app.Activity; 
import android.os.Bundle; 
import android.os.Handler; 
import android.view.View; 
 
public class MeiTuanManActivity extends Activity { 
 private MeituanProgressDialog dialog; 
 @Override 
 protected void onCreate(Bundle savedInstanceState) { 
 super.onCreate(savedInstanceState); 
 setContentView(R.layout.meituan_progressdialog); 
 } 
  
 public void showmeidialog(View v){ 
 dialog =new MeituanProgressDialog(this, "正在加载中",R.anim.frame_meituan); 
 dialog.show(); 
 Handler handler =new Handler(); 
 handler.postDelayed(new Runnable() { 
 @Override 
 public void run() { 
 dialog.dismiss(); 
 } 
 }, 3000);//3秒钟后调用dismiss方法隐藏; 
 } 
} 

最后,让我们的程序跑起来:

ok,跑起来了,你想要加入你的项目,只需要准备两张图片替换下来即可模拟动画。

您可能感兴趣的文章:Android中仿iOS提示框的实现方法Android使用Toast显示消息提示框IOS 仿Android吐司提示框的实例(分享)Android 自定义一套 Dialog通用提示框 (代码库)Android仿IOS自定义AlertDialog提示框Android仿QQ、微信聊天界面长按提示框效果Android仿百度谷歌搜索自动提示框AutoCompleteTextView简单应用示例Android超实用的Toast提示框优化分享Android实现Toast提示框图文并存的方法Android编程之自定义AlertDialog(退出提示框)用法实例android 弹出提示框的使用(图文实例)Android实现简单的popupwindow提示框


--结束END--

本文标题: Android模拟美团客户端进度提示框

本文链接: https://www.lsjlt.com/news/26546.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • 怎么在Android应用中模拟一个新闻客户端
    这期内容当中小编将会给大家带来有关怎么在Android应用中模拟一个新闻客户端,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。首先我们创建一个JsonParse类用来解析json文件:package cn....
    99+
    2023-05-31
    android roi
  • Android自定义ProgressBar实现漂亮的进度提示框
    在android智能平板设备应用中,一项耗时的操作总要有个提示进度的框来提高用户的操作体验,操作进度提示框就显得很常用了。 系统自带的有进度条ProgressBar,一般用于显示一个...
    99+
    2024-04-02
  • Android怎么自定义ProgressBar实现漂亮的进度提示框
    这篇文章主要介绍“Android怎么自定义ProgressBar实现漂亮的进度提示框”,在日常操作中,相信很多人在Android怎么自定义ProgressBar实现漂亮的进度提示框问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法...
    99+
    2023-07-02
  • 移动web模拟客户端如何实现多方框输入密码效果
    小编给大家分享一下移动web模拟客户端如何实现多方框输入密码效果,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!先看截图吧,大致的...
    99+
    2024-04-02
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作