是否可以将帧设置为动画图像,并将其设置为相对布局的背景

时间:2015-11-26 04:50:50

标签: android

我为动画图像编写了代码,并尝试将其设置为相对布局的背景,但它不起作用它只显示一个图像而不是动画图像。

package com.example.animation;

import android.os.Bundle;
import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.view.Menu;
import android.widget.ImageView;
import android.widget.RelativeLayout;

public class MainActivity extends Activity {
 //ImageView view;
 AnimationDrawable frameanimation;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
       // view = (ImageView) findViewById(R.id.imageView);

        RelativeLayout layout1=(RelativeLayout) findViewById(R.id.relative1);

        // Setting animation_list.xml as the background of the image view
           layout1.setBackgroundResource(R.drawable.anim);

        // Type casting the Animation drawable
        frameanimation = (AnimationDrawable) layout1.getBackground();

    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}

提前致谢?

1 个答案:

答案 0 :(得分:2)

在获取AnimationDrawable后,您还应该调用OPERATING_CARRIER='AB' OPERATING_CARRIER='EY' OPERATING_CARRIER='VA' FLIGHT_NO=604 FLIGHT_NO=603 STOCK='9W'

像这样:

frameanimation.start();
相关问题