OnUpdate()和OnDraw()

数据的初始化显示刚开始写在onupdate中,文档类中的数据更新之后,希望通过调用UpdateAllViews(FALSE)来实现视图的更新,可以实现!后来觉得不妥,想把初始化显示写在ondraw中,onupdate另有他用,结果框架调用onupdate之后却并不调用ondraw,可在另一个相同程序中却调用了ondraw,百思不得其解。

 原来是,onupdate的默认实现实现是通过发送WM_PAINT的消息调用ondraw的,一旦将update重载,就不在默认执行了,要想仍然调用ondraw,可以

return CView::OnUpdate(pSender, lHint, pHint);
实现默认调用。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是一个使用TextureView实现多点触摸控制的例子,包括移动、缩放和旋转: ```java public class MultiTouchTextureView extends TextureView implements TextureView.SurfaceTextureListener { private float mPosX, mPosY; private float mLastTouchX, mLastTouchY; private float mScaleFactor = 1.f; private float mLastGestureX, mLastGestureY; private float mRotationDegrees = 0.f; public MultiTouchTextureView(Context context) { this(context, null, 0); } public MultiTouchTextureView(Context context, AttributeSet attrs) { this(context, attrs, 0); } public MultiTouchTextureView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); setSurfaceTextureListener(this); } @Override public boolean onTouchEvent(MotionEvent event) { // Let the ScaleGestureDetector inspect all events. mScaleDetector.onTouchEvent(event); final int action = event.getAction(); switch (action & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: { final float x = event.getX(); final float y = event.getY(); mLastTouchX = x; mLastTouchY = y; break; } case MotionEvent.ACTION_MOVE: { final float x = event.getX(); final float y = event.getY(); // Only move if the ScaleGestureDetector isn't processing a gesture. if (!mScaleDetector.isInProgress()) { final float dx = x - mLastTouchX; final float dy = y - mLastTouchY; mPosX += dx; mPosY += dy; invalidate(); } mLastTouchX = x; mLastTouchY = y; break; } case MotionEvent.ACTION_UP: { break; } case MotionEvent.ACTION_CANCEL: { break; } case MotionEvent.ACTION_POINTER_UP: { break; } } return true; } private ScaleGestureDetector mScaleDetector = new ScaleGestureDetector(getContext(), new ScaleGestureDetector.SimpleOnScaleGestureListener() { @Override public boolean onScale(ScaleGestureDetector detector) { mScaleFactor *= detector.getScaleFactor(); // Don't let the object get too small or too large. mScaleFactor = Math.max(0.1f, Math.min(mScaleFactor, 5.0f)); invalidate(); return true; } }); @Override public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) { // Setup default size and position mPosX = width / 2.f; mPosY = height / 2.f; mLastGestureX = width / 2.f; mLastGestureY = height / 2.f; // Set the aspect ratio of the TextureView int aspectRatio = height > width ? height / width : width / height; setAspectRatio(aspectRatio); } @Override public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) { // Update default size and position when the TextureView size changes mPosX = width / 2.f; mPosY = height / 2.f; mLastGestureX = width / 2.f; mLastGestureY = height / 2.f; } @Override public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) { return true; } @Override public void onSurfaceTextureUpdated(SurfaceTexture surface) { } @Override public void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.save(); // Move the canvas to the center of the TextureView canvas.translate(mPosX, mPosY); // Scale the canvas based on the scale factor canvas.scale(mScaleFactor, mScaleFactor); // Rotate the canvas based on the rotation degrees canvas.rotate(mRotationDegrees); // Draw your content here // ... canvas.restore(); } } ``` 这个例子中,我们使用了TextureView作为视图容器,通过触摸事件实现多点触摸控制。在onTouchEvent方法中,我们处理了移动的逻辑,通过ScaleGestureDetector处理缩放的逻辑。在onDraw方法中,我们先将画布移动到TextureView的中心点,然后根据移动、缩放和旋转的参数对画布进行变换。你可以在onDraw方法中添加你自己的绘制逻辑。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值