Android: make a scrollable custom view

Posted by Martyn on Stack Overflow See other posts from Stack Overflow or by Martyn
Published on 2010-05-09T20:48:07Z Indexed on 2010/05/09 21:08 UTC
Read the original article Hit count: 221

Filed under:
|
|

Hey,

I've rolled my own custom view and can draw to the screen alright, but what I'd really like to do is set the measuredHeigh of the screen to, say, 1000px and let the user scroll on the Y axis, but I'm having problems doing this. Can anyone help?

Here's some code:

public class TestScreen extends Activity  {
     CustomDrawableView mCustomDrawableView;
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);    
         mCustomDrawableView = new CustomDrawableView(this);
         setContentView(mCustomDrawableView);
     }
 }

and

public class CustomDrawableView extends View {

    public CustomDrawableView(Context context) {
        super(context);
        setVerticalScrollBarEnabled(true);
        setMinimumHeight(1000);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        canvas.drawLine(...);
        // more drawing
    }
}

I've tried to override scrollTo, scrollBy, awakenScrollBars etc with a call to super but to no avail. Am I missing something silly, or am I making some fundamental mistake?

Thank you in advance,

Martyn

© Stack Overflow or respective owner

Related posts about android

Related posts about custom