小编Vic*_*dia的帖子

Android:从静止图像制作动画

我有一系列静态图像,总共有超过500个图像呈现在drawable目录中.我需要制作一个动画(每秒加载大约20个图像).我希望它能够顺利运行并且没有内存异常.

我想这样做,2至3秒(40到60张图像)的图像应该加载到内存中并显示,然后它们应该关闭(释放内存),然后加载下2到3秒的图像.此技术可以防止内存不足异常.它只是一个想法,我不知道它是否是一个好主意.请引导我一些更好的想法与一些代码一起...如果我的想法更好,可以工作,那么请告诉我一些帮助代码来做到这一点.

在阅读回复并按照您的建议进行操作后,我编写了一些代码,如下所示:

  <?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"
android:id="@+id/llMain">

<ViewFlipper android:id="@+id/imageflipper"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
<ImageView android:id="@+id/ImageView01"
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"        
        android:scaleType="centerInside"        
        android:layout_gravity="center" />
    </ViewFlipper>
    </LinearLayout>
Run Code Online (Sandbox Code Playgroud)

这是我做动画的代码:

public class Animation extends Activity {
ViewFlipper flipper;
int myIndex = 216;
private final Handler handler = new Handler();
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    flipper=(ViewFlipper)findViewById(R.id.imageflipper); 
    doTheAutoRefresh();
        //displayData();
}

private void doTheAutoRefresh() {
    handler.postDelayed(new Runnable() {
        public void run(){
            displayData(); // this …
Run Code Online (Sandbox Code Playgroud)

animation android image

14
推荐指数
2
解决办法
5万
查看次数

标签 统计

android ×1

animation ×1

image ×1