显示.gif注意与android.graphics.Movie [英] Show .gif with android.graphics.Movie

查看:493
本文介绍了显示.gif注意与android.graphics.Movie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想,创建一个GIF动画的视图。

I'm trying, create a view with an animated GIF..

当我尝试运行的后续code在模拟器一切工作正常。但是,当我在现实智能手机尽量跑,什么都不会发生。

When i try run the follow code in emulator all works fine. But when i try run in real Smart Phone, nothing happens..

我的看法:

public class GIFView extends View {

private Movie mMovie;
private long movieStart;

public GIFView(Context context) {
    super(context);
    initializeView();
}

public GIFView(Context context, AttributeSet attrs) {
    super(context, attrs);
    initializeView();
}

public GIFView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    initializeView();
}

private void initializeView() {
    InputStream is = getContext().getResources().openRawResource(
            R.drawable.cookies2);
    mMovie = Movie.decodeStream(is);
}

protected void onDraw(Canvas canvas) {
    canvas.drawColor(Color.TRANSPARENT);
    super.onDraw(canvas);
    long now = android.os.SystemClock.uptimeMillis();

    if (movieStart == 0) {
        movieStart = (int) now;
    }
    if (mMovie != null) {
        int relTime = (int) ((now - movieStart) % mMovie.duration());
        mMovie.setTime(relTime);
        mMovie.draw(canvas, getWidth() - mMovie.width(), getHeight()
                - mMovie.height());
        this.invalidate();
    }
}}

我的活动:

public class MainActivity extends Activity {
    public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     GIFView gifView = new GIFView(this);
     setContentView(gifView);
}}

我的智能手机屏幕截图: 我的模拟器截图:

My Smartphone screenshot: My emulator screenshot:

为何我的应用程序不会在智能手机上运行?

Why my app doesn't run in smartphone?

推荐答案

不要关闭硬件加速整个应用程序。这是沉重的。只需将其关闭的观点:

Don't turn off hardware acceleration for the whole application. That's crippling. Just turn it off for the view:

setLayerType(View.LAYER_TYPE_SOFTWARE, null);

这篇关于显示.gif注意与android.graphics.Movie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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