Forum: Ruby on Rails canvas scroll

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
44999b12bbad1b498252b3ac60c3ab0f?d=identicon&s=25 Maulin pa (mpathare)
on 2009-05-18 20:14
(Received via mailing list)
I am writing a solitaire app. I use a canvas to draw everything on the
screen. Sometimes a pile of cards will get big and extend below the
bottom of the screen. I would like to make the canvas scrollable so
the user can access those cards.

Main Activity.

package com.maulinpathare.solitaire;

public class Solitaire extends Activity{
    /** Called when the activity is first created. */
     private Context mContext;
     private GameView mG;

    public void onCreate(Bundle savedInstanceState) {
        mContext = this;

    public boolean onCreateOptionsMenu(Menu menu) {
        boolean result = super.onCreateOptionsMenu(menu);
        menu.add(0, 1, 0, R.string.newGame);
        menu.add(0, 2, 0, R.string.exitGame);
        return result;

    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case 1:
          mG = new GameView(this);
            return true;
        case 2:
            return true;
        return false;

}//end class

GameView Class
This is where everything happens
I have removed most of the game logic...

package com.maulinpathare.solitaire;

public class GameView extends ScrollView implements OnTouchListener{
     private Deck mD;
     private boolean mInit, mDone;
     private Stack<Card> mPile1, mPile2, mPile3, mPile4, mPile5,
mPile6, mPile7,
                              mOpenPile, mEndPile1, mEndPile2,
mEndPile3, mEndPile4, mTemp;
     private Canvas mCanvas;
     private int mPile;
     private boolean mPickUp, mVictory;
     private Card mCard;
     private final int mSpacing = 22;
     private Paint rectPaint, wonPaint1, wonPaint2;

     public GameView(Context context) {
                    //initialize everything needed for the game

    protected void onDraw(Canvas canvas) {
     mCanvas = canvas;
          mInit = false;
        //draw stuff...

    }//end onDraw

    public boolean onTouch(View v, MotionEvent event){
     int eventAction = event.getAction();
     int x = Math.round(event.getX());
     int y = Math.round(event.getY());

     case MotionEvent.ACTION_DOWN:
                    //check if touch has happened on one of the card
          break; //end case action_touch

     case MotionEvent.ACTION_MOVE:
                    //if card touched move it
          break; //end case action_move

     case MotionEvent.ACTION_UP:
                    //check if legal move has been made
          break; //end case action_up

     }//end switch(event)

     return true;
    }//end onTouch

Where and how should I implement screen scrolling? I would like the
user to be able to slide their finger across the screen in the
direction they want to scroll.
This topic is locked and can not be replied to.