我的GIF图像示于仿真器,但缺少在我的智能手机我的、仿真器、智能手机、图像

2023-09-05 08:44:58 作者:薄情辞

在我的应用程序,我这显示在模拟器完全workd几个GIF图像,但是当我安装apk文件在智能手机上的应用程序工作正常,但GIF图像不显示,任何的解释,为什么?

in my application i am displaying a few gif images which workd perfectly in emulator but when i install the apk file in my smartphone the application works as normal but gif images are not displayed , any explanation why ??

这是我的code的视图GIF显示

here is my code for the view for gif display

import android.content.Context;
import java.io.InputStream;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Movie;
import android.os.SystemClock;
import android.view.View;

public class GifWebView extends View {
    private Movie mMovie;
    InputStream mStream;
    long mMoviestart;

    public GifWebView(Context context, InputStream stream) {
        super(context);
        mStream = stream;
        mMovie = Movie.decodeStream(mStream);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        canvas.drawColor(Color.TRANSPARENT);
        super.onDraw(canvas);
        final long now = SystemClock.uptimeMillis();

        if (mMoviestart == 0) 
        {
            mMoviestart = now;
        }
        int gif_image_duration = mMovie.duration();
        if(gif_image_duration==0)
        {
            gif_image_duration = 1;
        }
        final int relTime = (int) ((now - mMoviestart) % gif_image_duration);
        mMovie.setTime(relTime);
        mMovie.draw(canvas, 10, 10);
        this.invalidate();
    }
}

和我的活动我称之为

GifWebView gif_view;// as global var

在我上创建方法

and in my on create method

    gif_linear_layout = (LinearLayout)findViewById(R.id.gif_linear_layout);
InputStream stream = null;
            try {
                stream = getAssets().open(gif_name);
                //stream = getAssets().open("gif_images").;
            } 
            catch (IOException e) 
            {
                e.printStackTrace();
            }
            gif_view = new GifWebView(this, stream);
            gif_linear_layout.addView(gif_view);

这是它的样子第1部分:在仿真器第2部分:我的智能响度

this is how it looks like part 1 : on emulator part 2 : on my smart phon

推荐答案

我面临同样的问题。如果您确信您的code是好的,那么就加入安卓hardwareAccelerated =假在您的本次活动的清单。希望这将解决您的问题。

I was face the same problem. If you are confident your code is ok, then just add android:hardwareAccelerated="false" in your manifest of your this activity. Hope it will solve your problem.