当前位置: 首页 > 编程笔记 >

Android之仿美团加载数据帧动画

沈飞翔
2023-03-14
本文向大家介绍Android之仿美团加载数据帧动画,包括了Android之仿美团加载数据帧动画的使用技巧和注意事项,需要的朋友参考一下

一:先来张效果图(这里是GIF动画,我就截屏的所有没有动画,实际是动的):

二:实现步骤:

1、xml布局

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical">
  <TextView
    android:id="@+id/textview"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_alignParentBottom="true"
    android:layout_margin="20dp"
    android:background="@drawable/animationtk"
    android:gravity="center"
    android:text="点击弹出动画"
    android:textColor="#fff"
    android:textSize="18dp" />
</RelativeLayout>

2.activity代码

package cll.com.myapplication;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

/**
 * @Description 奔跑小人的动画弹框,可以用作加载数据界面
 * 2017-4-3 http://blog.csdn.net/android_cll
 */
public class RuningManActivity extends Activity implements View.OnClickListener {
  private TextView textview;//点击按钮
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.ac_runing_man);
    initlayout();
  }
  /**
   * 实例化
   */
  private void initlayout() {
    textview = (TextView) findViewById(R.id.textview);
    textview.setOnClickListener(this);
  }
  /**
   * 显示美团进度对话框
   *
   * @param v
   */
  public void showmeidialog(View v) {
    CustomProgressDialog dialog = new CustomProgressDialog(this, "正在加载中......", R.anim.animation);
    dialog.setCanceledOnTouchOutside(false);//设置是否可以点击外部消失
    dialog.setCancelable(false);//设置是否可以按退回键取消
    dialog.show();
  }
  @Override
  public void onClick(View view) {
    switch (view.getId()) {
      case R.id.textview:
        showmeidialog(view);
        break;
    }
  }
}

3.自定义弹框工具类

package cll.com.myapplication;
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;
/**
 * @Description:自定义加载数据弹框
 * @author 2017-4-3 http://blog.csdn.net/android_cll
 */
public class CustomProgressDialog extends ProgressDialog {
  private AnimationDrawable mAnimation;
  private ImageView mImageView;
  private String mLoadingTip;
  private TextView mLoadingTv;
  private int mResid;
  public CustomProgressDialog(Context context, String content, int id) {
   super(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();
   // 为了防止在onCreate方法中只显示第一帧的解决方案之一
   mImageView.post(new Runnable() {
     @Override
     public void run() {
      mAnimation.start();
     }
   });
   mLoadingTv.setText(mLoadingTip);
  }
  private void initView() {
   setContentView(R.layout.progress_dialog);
   mLoadingTv = (TextView) findViewById(R.id.loadingTv);
   mImageView = (ImageView) findViewById(R.id.loadingIv);
  }
}

4.自定义弹框的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/animation"/>
  <TextView
    android:id="@+id/loadingTv"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
   android:layout_alignBottom="@+id/loadingIv"
   android:textColor="#fff"
   android:layout_centerHorizontal="true"
   android:textSize="20sp"
    android:text="正在加载中.." />
</RelativeLayout>

5.anim文件下的帧动画文件

<?xml version="1.0" encoding="utf-8"?> 
<animation-list 
  android:oneshot="false"
  xmlns:android="http://schemas.android.com/apk/res/android" 
  >  
  <item android:drawable="@mipmap/progress_loading_image" android:duration="150"/>
   <item android:drawable="@mipmap/progress_loading_imagey" android:duration="150"/>
</animation-list>  

到此加载数据弹框的帧动画功能就实现了,不喜勿喷,都有注释就不用解释太多

最后附上源码:http://download.csdn.net/download/android_cll/9802503

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持小牛知识库!

 类似资料:
  • 本文向大家介绍Android实现仿美团、顺丰快递数据加载效果,包括了Android实现仿美团、顺丰快递数据加载效果的使用技巧和注意事项,需要的朋友参考一下 我们都知道在Android中,常见的动画模式有两种:一种是帧动画(Frame Animation),一种是补间动画(Tween Animation)。帧动画是提供了一种逐帧播放图片的动画方式,播放事先做好的图像,与gif图片原理类似,就像是在放

  • 本文向大家介绍Android ViewDragHelper仿淘宝拖动加载效果,包括了Android ViewDragHelper仿淘宝拖动加载效果的使用技巧和注意事项,需要的朋友参考一下 拖动加载是我在淘宝的商品详情界面发现的,感觉很实用。于是就分析它的实现方式,感觉用ViewDragHelper可以很方便的实现这种效果。下面大致把我的思路分步骤写一下。先上图吧。 首先建工程什么的我就不多说了。咱

  • 本文向大家介绍Android自定义加载控件实现数据加载动画,包括了Android自定义加载控件实现数据加载动画的使用技巧和注意事项,需要的朋友参考一下 本文实例为大家分享了Android自定义加载控件,第一次小人跑动的加载效果眼前一亮,相比传统的PrograssBar高大上不止一点,于是走起,自定义了控件LoadingView去实现动态效果,可直接在xml中使用,具体实现如下 2. xml布局文件

  • 本文向大家介绍iscroll动态加载数据完美解决方法,包括了iscroll动态加载数据完美解决方法的使用技巧和注意事项,需要的朋友参考一下 本文实例为大家分享了iscroll动态加载数据的具体代码,供大家参考,具体内容如下 js. css 以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持呐喊教程。

  • 假设我有一个空的dataframe,已经设置了列,但没有行。我从网上搜集了一些数据,所以假设我需要向空数据帧添加一个索引< code>'2176'。当我试图分配该行时,如何自动将它添加到数据库中?这是熊猫的目的还是我应该用别的东西?

  • 主要内容:本节引言:,1.帧动画概念以及用法,2.使用示例:,3.本节示例代码和Gif帧提取工具下载,本节小结:本节引言: 从本节开始我们来探究Android中的动画,毕竟在APP中添加上一些动画,会让我们的应用变得 很炫,比如最简单的关开Activity,当然自定义控件动画肯定必不可少啦~而Android中的动画 分为三大类,逐帧动画(Frame)以及补间动画(Tween),还有Android 3.0以后引入的属性动画 (Property),而本节给大家带来的是第一种动画——逐帧动画的一个基本