[自定义ScrollView无法滚动

时间:2012-07-03 08:00:37

标签: android scrollview

我有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();
}

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

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