0

我有一个CustomScrollView扩展ScrollView,然后我在方法中做一些事情OnDraw()。不幸的是,CustomScrollView不能再滚动了,这是我所做的代码。

@Override
protected void onDraw(Canvas canvas){
    super.onDraw(canvas);
    Log.d(null,"current measured height is:"+getMeasuredHeight());
    Log.d(null,"screen height is:"+mScreenHeight);

    Rect rect=new Rect(50,0,mScreenWidth-50,mScreenHeight<<1);
    canvas.drawRect(rect,mFilledPaint);
}

@Override
public void onMeasure(int widthMeasureSpec,int heightMeasureSpec){
    super.onMeasure(widthMeasureSpec,heightMeasureSpec);
    setMeasuredDimension((int)mScreenWidth,(int)mScreenHeight<<1);
}

private void init(){
    mFilledPaint.setStyle(Paint.Style.FILL);
    mFilledPaint.setColor(Color.WHITE);

    mScreenWidth=((Activity)mContext).getWindowManager().getDefaultDisplay().getWidth();
    mScreenHeight=((Activity)mContext).getWindowManager().getDefaultDisplay().getHeight();
}
4

2 回答 2

0

尝试在自定义中编写这些代码View(只需让您的类扩展View)并将其添加到ScrollView. 覆盖ScrollView方法将禁用其默认行为,如滚动。

于 2012-07-03T09:02:16.340 回答
0

如果您只需要绘制额外的东西,请删除 onMeasure 覆盖。

于 2012-07-03T09:04:10.177 回答