Info about the Movie class for Android

前端 未结 3 544
梦如初夏
梦如初夏 2021-01-05 22:14

I\'m trying to show an animated gif. By the way I\'m doing it with the class Movie. But the Android Developer page dont grant info about the methods.

How can I make

3条回答
  •  失恋的感觉
    2021-01-05 22:35

    I know, this is very old post.

    But you can try this ...

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    
        if (mMovie != null) {
            int movieWidth = mMovie.width();
            int movieHeight = mMovie.height();
    
    
             /** Calculate horizontal scaling*/
    
            float scaleH = 1f;
            int measureModeWidth = MeasureSpec.getMode(widthMeasureSpec);
    
            if (measureModeWidth != MeasureSpec.UNSPECIFIED) {
                int maximumWidth = MeasureSpec.getSize(widthMeasureSpec);
                if (movieWidth > maximumWidth) {
                    scaleH = (float) movieWidth / (float) maximumWidth;
                }else{
                    scaleH = (float) maximumWidth / (float) movieWidth;
                }
            }
    
    
             /** calculate vertical scaling*/
    
            float scaleW = 1f;
            int measureModeHeight = MeasureSpec.getMode(heightMeasureSpec);
    
            if (measureModeHeight != MeasureSpec.UNSPECIFIED) {
                int maximumHeight = MeasureSpec.getSize(heightMeasureSpec);
                if (movieHeight > maximumHeight) {
                    scaleW = (float) movieHeight / (float) maximumHeight;
                }else{
                    scaleW = (float) maximumHeight / (float) movieHeight;
                }
            }
    
    
             /** calculate overall scale*/
    
            mScale = Math.max(scaleH, scaleW);
    
            mMeasuredMovieWidth = (int) (movieWidth * mScale);
            mMeasuredMovieHeight = (int) (movieHeight * mScale);
    
            setMeasuredDimension(widthMeasureSpec, heightMeasureSpec);
    
        } else {
    
             /*No movie set, just set minimum available size.*/
    
            setMeasuredDimension(getSuggestedMinimumWidth(), getSuggestedMinimumHeight());
        }
    }
    
    private void drawMovieFrame(Canvas canvas) {
    
        mMovie.setTime(mCurrentAnimationTime);
    
        canvas.save(Canvas.MATRIX_SAVE_FLAG);
        canvas.scale(mScale, mScale);
                mLeft = (getWidth() - mMeasuredMovieWidth) / 2f;
        mTop = (getHeight() - mMeasuredMovieHeight) / 2f;
        mMovie.draw(canvas, mLeft / mScale, mTop / mScale);
        canvas.restore();
    }
    

提交回复
热议问题