Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/204.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android:gif图像在android中从webservice获取数据时不会循环_Android_Web Services_Gif - Fatal编程技术网

android:gif图像在android中从webservice获取数据时不会循环

android:gif图像在android中从webservice获取数据时不会循环,android,web-services,gif,Android,Web Services,Gif,我是android新手,我想以gif格式显示正在加载的图像。在谷歌搜索后,我发现: 吉维: package ComponentGif; import java.io.InputStream; import android.content.Context; import android.graphics.Canvas; import android.graphics.Movie; import android.util.AttributeSet; import android.view.Vie

我是android新手,我想以gif格式显示正在加载的图像。在谷歌搜索后,我发现:

吉维:

package ComponentGif;

import java.io.InputStream;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Movie;
import android.util.AttributeSet;
import android.view.View;

public class GifView extends View {

    private InputStream gifInputStream;
    private Movie gifMovie;
    private int movieWidth, movieHeight;
    private long movieDuration;
    private long mMovieStart;
    private Canvas _canvas = null;

    public GifView(Context context) {
        super(context);
        init(context);
    }

    public GifView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public GifView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    private void init(Context context) {
        setFocusable(true);
        gifInputStream = context.getResources().openRawResource(com.example.agency.R.drawable.loading);

        gifMovie = Movie.decodeStream(gifInputStream);
        movieWidth = gifMovie.width();
        movieHeight = gifMovie.height();
        movieDuration = gifMovie.duration();
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        setMeasuredDimension(movieWidth, movieHeight);
    }

    public int getMovieWidth() {
        return movieWidth;
    }

    public int getMovieHeight() {
        return movieHeight;
    }

    public long getMovieDuration() {
        return movieDuration;
    }

    @Override
    protected void onDraw(Canvas canvas) {
        long now = android.os.SystemClock.uptimeMillis();
        if (mMovieStart == 0) { // first time
            mMovieStart = now;
        }

        if (gifMovie != null) {

            int dur = gifMovie.duration();
            if (dur == 0) {
                dur = 1000;
            }

            int relTime = (int) ((now - mMovieStart) % dur);

            gifMovie.setTime(relTime);

            gifMovie.draw(canvas, 0, 0);

            invalidate();

        }
    }

}
在主活动xml中,我添加了以下内容:

> <ComponentGif.GifView
>         android:id="@+id/imgWaitLoading"
>         android:layout_width="wrap_content"
>         android:layout_height="30dp"
>         android:layout_marginBottom="30dp"
>         android:layout_marginLeft="90dp" />
android:id=“@+id/imgWaitLoading” >android:layout\u width=“包装内容” >android:layout_height=“30dp” >android:layout_marginBottom=“30dp” >android:layout_marginLeft=“90dp”/>
我正在使用webservice获取数据(连接internet),图像在从webservice获取数据完成后开始循环。为什么?

听起来像是从UI线程调用web服务听起来像是从UI线程调用web服务