java– 我需要简单的Android动画示例

java– 我需要简单的Android动画示例,第1张

概述请给我简单的Android动画示例和XML.我是Android的新手,我需要明确的解释.解决方法:试试这个希望你找到有趣的..这是活动代码……packagetest.example;importandroid.app.Activity;importandroid.graphics.drawable.AnimationDrawable;importandroid.graphics.drawable.B

请给我简单的Android动画示例和XML.我是AndroID的新手,我需要明确的解释.

解决方法:

试试这个希望你找到有趣的..

这是活动代码……

package test.example;import androID.app.Activity;import androID.graphics.drawable.AnimationDrawable;import androID.graphics.drawable.BitmapDrawable;import androID.os.Bundle;import androID.vIEw.VIEw;import androID.vIEw.VIEw.OnClickListener;import androID.Widget.button;import androID.Widget.ImageVIEw;public class AminationDemo extends Activity implements OnClickListener {    ImageVIEw img;    button strtbtn,stpbtn;    AnimationDrawable mAnimation;    /** Called when the activity is first created. */    @OverrIDe    public voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.main);        img = (ImageVIEw) findVIEwByID(R.ID.iv);        BitmapDrawable frame0 = (BitmapDrawable)getResources().getDrawable(R.drawable.f0);        BitmapDrawable frame1 = (BitmapDrawable)getResources().getDrawable(R.drawable.f1);        BitmapDrawable frame2 = (BitmapDrawable)getResources().getDrawable(R.drawable.f2);        BitmapDrawable frame3 = (BitmapDrawable)getResources().getDrawable(R.drawable.f3);        BitmapDrawable frame4 = (BitmapDrawable)getResources().getDrawable(R.drawable.f4);        BitmapDrawable frame5 = (BitmapDrawable)getResources().getDrawable(R.drawable.f5);        int reasonableDuration = 750;        mAnimation = new AnimationDrawable();        mAnimation.addFrame(frame0, reasonableDuration);        mAnimation.addFrame(frame1, reasonableDuration);        mAnimation.addFrame(frame2, reasonableDuration);        mAnimation.addFrame(frame3, reasonableDuration);        mAnimation.addFrame(frame4, reasonableDuration);        mAnimation.addFrame(frame5, reasonableDuration);        img.setBackgroundDrawable(mAnimation);                strtbtn = (button) findVIEwByID(R.ID.strtbtn);        strtbtn.setonClickListener(this);        stpbtn = (button) findVIEwByID(R.ID.stpbtn);        stpbtn.setonClickListener(this);    }    @OverrIDe    public voID onClick(VIEw v) {      if(v.getID()== R.ID.strtbtn){          mAnimation.start();          mAnimation.setoneshot(false);      }      else        mAnimation.stop();    }  }

布局主要……

<?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"    ><ImageVIEw      androID:ID="@+ID/iv"    androID:layout_wIDth="400dp"     androID:layout_height="250dp" /><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:orIEntation="horizontal"    androID:layout_wIDth="fill_parent"    androID:layout_height="fill_parent"    >    <button         androID:layout_height="wrap_content"         androID:ID="@+ID/strtbtn"         androID:layout_wIDth="wrap_content"         androID:text="start"        />        <button         androID:layout_height="wrap_content"         androID:ID="@+ID/stpbtn"         androID:layout_wIDth="wrap_content"         androID:text="stop"        />    </linearLayout></linearLayout>

这里是帧,例如你可以创建自己的…(放入名称为f0,f1,…的drawable)

总结

以上是内存溢出为你收集整理的java – 我需要简单的Android动画示例全部内容,希望文章能够帮你解决java – 我需要简单的Android动画示例所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1097729.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存