0

ここに画像の説明を入力 親の線形レイアウト

        <LinearLayout
        android:id="@+id/gif_linear_layout"
        android:background="@drawable/shape"
        android:layout_marginTop="5dp"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:orientation="vertical" />

だから私はこのクラスGifWebViewを持っています

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();
    }
}

メインアクティビティでこのクラスのインスタンスを作成して、メインアクティビティで完全に機能するgif画像を表示します

GifWebView gif_view;//global var

// already existing linear layout in my layout file 

// and then this in onCreate() 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.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
        gif_linear_layout.addView(gif_view);

GifWebVIew クラスのインスタンスを作成することによって作成されたビューのレイアウト パラメータを設定する方法を教えてください。

実際には、インスタンス ビューを線形レイアウトに完全に適合させたいのですが、適合しません。

何か助けて提案してください。

4

2 に答える 2