在特定帧显示敬酒消息 [英] toast message displayed at specific frames

查看:365
本文介绍了在特定帧显示敬酒消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要敬酒的消息在我的Andr​​oid应用程序在我的动画特定帧开始。下面我发布存储我的帧xml文件。

 <?XML版本=1.0编码=UTF-8&GT?;
<动画列表的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:单稳=假>
<项目机器人:可绘制=@绘制/ SY1机器人:时间=210/>
<项目机器人:可绘制=@绘制/ SY2机器人:时间=210/>
<项目机器人:可绘制=@绘制/ SY3机器人:时间=210/>
<项目机器人:可绘制=@绘制/ SY4机器人:时间=210/>
<项目机器人:可绘制=@绘制/ SY5机器人:时间=210/>
<项目机器人:可绘制=@绘制/ SY6机器人:时间=210/>
< /动漫列表>


解决方案

假设你想显示在4帧敬酒消息。通过计算显示敬酒时间 animationDrawable.getDuration(int i)以

  INT STARTING_FRAME = 4;
INT TOTALTIME = 0;
的for(int i = 0; I< STARTING_FRAME;我++){
  TOTALTIME = + animationDrawable.getDuration(I)
}

现在,只要你启动动画,使用显示举杯 handler.postDelayed(Runnable的R,长delayMillis)

  animationDrawable.start();
新的处理程序()。postDelayed(新的Runnable(){
  @覆盖
  公共无效的run(){
    Toast.makeText(背景下,吐司文本,Toast.LENGTH_SHORT).show();
  }
}, 总时间);

I want toast messages to start in my android application at specific frames in my animation. Below I have posted the xml file which stores my frames.

<?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/sy1" android:duration="210" />
<item android:drawable="@drawable/sy2" android:duration="210" />
<item android:drawable="@drawable/sy3" android:duration="210" />
<item android:drawable="@drawable/sy4" android:duration="210" />
<item android:drawable="@drawable/sy5" android:duration="210" />
<item android:drawable="@drawable/sy6" android:duration="210" />
</animation-list>

解决方案

Suppose you want to show a toast message at 4th frame. Calculate the time to show the toast using animationDrawable.getDuration(int i).

int STARTING_FRAME = 4;
int totalTime = 0;
for (int i = 0; i < STARTING_FRAME; i++) {
  totalTime =+ animationDrawable.getDuration(i);
}

Now, as soon as you start the animation, show a toast using handler.postDelayed(Runnable r, long delayMillis).

animationDrawable.start();
new Handler().postDelayed(new Runnable() {
  @Override
  public void run() {
    Toast.makeText(context, "Toast text", Toast.LENGTH_SHORT).show();
  }
}, totalTime);

这篇关于在特定帧显示敬酒消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆