嵌入水平滚动视图中的视图是否会导致无限的 ondraw 调用
我有一个嵌入水平滚动条内的自定义视图。我注意到我的 ondraw 方法不断被调用。是因为水平滚动条吗?
这是我的 ondraw 函数:-
@Override
public void onDraw(Canvas canvas) {
Log.w(this.getClass().getName(),"onDraw of Balls called");
BallsOnDraw(canvas);
}
void BallsOnDraw(Canvas canvas)
{
canvas.drawLine(0, 240, 160, 0, mPaint);
canvas.drawLine(160, 0, 320, 240, mPaint);
TranslateAnimation mTrans = new TranslateAnimation(0, 320, 0,240);
mTrans.setDuration(6000);
SitoliaActivity.mBal.startAnimation(mTrans);
}
I have a cutom view which is embedded inside a horizontal scroll bar.I notice that my ondraw method is continously being called.Is it because of horizontal scroll bar?
here is my ondraw function:-
@Override
public void onDraw(Canvas canvas) {
Log.w(this.getClass().getName(),"onDraw of Balls called");
BallsOnDraw(canvas);
}
void BallsOnDraw(Canvas canvas)
{
canvas.drawLine(0, 240, 160, 0, mPaint);
canvas.drawLine(160, 0, 320, 240, mPaint);
TranslateAnimation mTrans = new TranslateAnimation(0, 320, 0,240);
mTrans.setDuration(6000);
SitoliaActivity.mBal.startAnimation(mTrans);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是正常的 Android 系统总是调用 onDraw() 因为它是在画布上绘制视图的方法 http://developer.android.com/reference/android/view/View.html#onDraw(android.graphics.Canvas)
This is normal the Android system always calls onDraw() cause it's the method that the view gets drawn on the canvas http://developer.android.com/reference/android/view/View.html#onDraw(android.graphics.Canvas)