Android frame 动画 (10k图片) 超过15张 报内存溢出

本文介绍如何使用XML定义动画列表,并在Android应用中实现简单的帧动画。通过设置android:oneshot属性控制动画播放行为,适用于小数量图片制作轻量级动画。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


在 xml中  按顺序添加动画的图片 ,如果每张10k左右  最多添加15张左右 会报内存溢出的异常    所以适合少量的图片做的动画

android:oneshot="true"属性 设置是否自动播放。

<?xml version="1.0" encoding="utf-8"?>

<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:oneshot="true" >


      <item
        android:drawable="@drawable/f1_00000" android:duration="35"/>
    <item
android:drawable="@drawable/f1_00001"  android:duration="35"/>
   <item
        android:drawable="@drawable/f1_00002"android:duration="35"/>
    <item
        android:drawable="@drawable/f1_00003"  android:duration="35"/>
  <item

        android:drawable="@drawable/f1_00004" android:duration="35"/>

</animation-list>



2  在布局中应用

  <ImageView  
    android:id="@+id/frame_image"  
    android:layout_width="fill_parent"  
    android:layout_height="fill_parent"  
    android:layout_weight="1"/> 


3 java中的代码 

  


private ImageView image;  
     
   @Override  
   protected void onCreate(Bundle savedInstanceState) {  
       super.onCreate(savedInstanceState);  
       setContentView(R.layout.solofengs);  
       image = (ImageView) findViewById(R.id.frame_image);  
   }  
     
   @Override  
   public void onWindowFocusChanged(boolean hasFocus) {  
       super.onWindowFocusChanged(hasFocus);  
       image.setBackgroundResource(R.anim.solofeng);  
       AnimationDrawable anim = (AnimationDrawable) image.getBackground(); 
    
       anim.start();  
   }  





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值