我有一个滚动视图,我将它添加到我的自定义视图中,在 customview 中覆盖 onMeasure 和 onTouchEvent,但是当我滚动它时没有绘制任何内容。
protected final void onDraw(Canvas paramCanvas)
{
int text_width;
int yCanvas;
yCanvas = paramCanvas.getClipBounds().top;
int h = paramCanvas.getClipBounds().height() ;
int hView = this.getHeight() ;
int topView = this.getTop();
paramCanvas.drawText("text...yCanvas :"+yCanvas + " --- hCanvas:"+h +"--- hView" + hView + " ----topView"+topView, 20, yCanvas+200, new Paint());
}
@Override
public boolean onTouchEvent(MotionEvent event) {
boolean res = super.onTouchEvent(event);
postInvalidate();
System.out.println("result: " + res);
return res;
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int h = 1000;
setMeasuredDimension(View.MeasureSpec.getSize(widthMeasureSpec), h);}
有趣的是,在所有平板电脑中 mycanvas 高度与视图高度相等,但在其他设备中 canvas.heigh() 与高度显示完全相等。