view.invalidate()不工作重绘的ImageView [英] view.invalidate() not working to redraw imageview

查看:1662
本文介绍了view.invalidate()不工作重绘的ImageView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好球员,这听起来愚蠢的,但我一直在敲我的头靠在键盘有一段时间了试图找出为什么这个不会刷新。基础知识:我有我测试,以看看我是否能围绕一个点旋转的图像度的X数量有点示例应用程序,并显示在同一时间做出流畅的动画一度。所以,我有一个伟大的样本,我发现有一个滑块的伟大工程,图像旋转基本上设置为一个点滑动条上,太棒了!但是....当我尝试创造一个for循环的随机数,并用我的变量沿途更新图像每一度...什么也不做......和我得到​​的是在最后的更新图像......但是当我拖我的手指上,他滑动条图形的即时更新和我纺纱......我无法弄清楚我在做什么错在这里......这里是code。与滑块..我没有我的作品,创建随机数并绘制它但本质上我做了一个按钮,点击后面

基本上,如果你看看这片我做了一个按钮后面一样了,但它不这样做实时。我叫view.invalidate()和view.postinvalidate(),试图迫使它,但没有去...

  @覆盖
   公共无效onProgressChanged(搜索栏搜索栏,INT进步,
     布尔FROMUSER){
    // TODO自动生成方法存根
    curRotate =(浮动)的进展情况;
    drawMatrix();
   }私人无效drawMatrix(){    字模=新的Matrix();
       matrix.postScale(curScale,curScale);
       matrix.postRotate(curRotate);       位图resizedBitmap = Bitmap.createBitmap(位图,0,0,bmpWidth,bmpHeight,矩阵,真);
       myImageView.setImageBitmap(resizedBitmap);   }


解决方案

我觉得你做了什么,是这样的:

 的for(int度= 0;学位与LT; maxRotation;我++){
    //执行由矩阵旋转
    myImageView.invalidate();
}

这不会因为工作无效()只时间表在主线程事件队列重绘。这意味着,只有当当前code具有所有被执行重绘将执行(在这种情况下,为循环)。

对于简单的旋转吐温动画会更适合。对于更高级的东西(如游戏中的动画),你可能需要创建一个自定义视图或使用​​ SurfaceView

Ok guys, this may sound dumb, but I have been banging my head against the keyboard for some time now trying to figure out why this will not refresh. the basics: I have a little sample app that i am testing to see if i can rotate an image around a point a X amount of degrees, and show it one degree at a time to make a smooth animation. So I have a great sample i found that works great with a slider bar, basically setting the images rotation to a point on the slider bar, great! but.... when i try and create a for loop with a random number and use my for variable updating the image along the way every degree... it does nothing... and all i get is the updated image at the end... but when i drag my finger on he slider bar the graphic is updated instant as me spinning it... I cant figure out what i am doing wrong here... here is the code with the slider... i don't have my piece that creates the random number and draws it but essentially i did it behind a button click

essentially if you look at this piece i did the same behind a button again but it doesnt do it "real time". i called view.invalidate() and view.postinvalidate() to try to force it but no go...

 @Override
   public void onProgressChanged(SeekBar seekBar, int progress,
     boolean fromUser) {
    // TODO Auto-generated method stub
    curRotate = (float)progress;
    drawMatrix();
   }

private void drawMatrix(){

    Matrix matrix = new Matrix();
       matrix.postScale(curScale, curScale);
       matrix.postRotate(curRotate);

       Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0, bmpWidth, bmpHeight, matrix, true);
       myImageView.setImageBitmap(resizedBitmap);

   }

解决方案

I think what you did was something like:

for (int degrees = 0 ; degrees < maxRotation ; i++) {
    // perform the rotation by matrix
    myImageView.invalidate();
}

This wouldn't work because invalidate() only schedules a redraw in the main thread event queue. This means that the redraw will be performed only when the current code has all been executed (in this case, the for cycle).

For a simple rotation a Tween Animation would be better suited. For more advanced stuff (like game animations) you might need to create a custom view or use SurfaceView.

这篇关于view.invalidate()不工作重绘的ImageView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆