pav*_*van 3 android view animated-gif
我正在使用电影类播放 gif 动画文件,但无法适合屏幕。
如何缩放或适合屏幕尺寸的 gif 文件?
我已经采用 GIF 视图自定义视图并使用 Movie 类播放动画。
试试这个 GifImageView
   init()
    {
        WindowManager wManager = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
        Display display = wManager.getDefaultDisplay();
        float screenwidth = display.getWidth();
        float screenheight = display.getHeight();
        mWidth = (int) screenwidth;
        mHeight = (int) screenheight;
        //Then force invalidated the layout of this view.
        requestLayout();
    }
活动如下所示:
@Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.myactivity);
        GifImageView gifImageView = (GifImageView) findViewById(R.id.GifImageView);
        gifImageView.setGifImageResource(R.drawable.my_gif);
    }
在我们的自定义布局中,我们再次需要以下内容:
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {     
        setMeasuredDimension(mWidth, mHeight);
}
@Override
protected void onDraw(Canvas canvas) {
        //Other general code (included in given link)...
        if (mMovie != null) {
            //Other general code (included in given link)...
            canvas.scale((float) this.getWidth() / (float) mMovie.width(),
                    (float) this.getHeight() / (float) mMovie.height());
            mMovie.draw(canvas, 0, 0);          
            invalidate();
        }
}
我已根据我们的要求定制了此视图。
https://github.com/NihalPandya/demoUpload/blob/master/GifImageView.java
| 归档时间: | 
 | 
| 查看次数: | 8598 次 | 
| 最近记录: |