Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jul 2011
    Posts
    44
    Thanks
    5
    Thanked 0 Times in 0 Posts

    scrolling canvas android

    Hello what I want to do is add a "scroll bar" to the right hand side of of the screen via java not XML layout how would I accomplish this?

    preferably with comments so I can learn from it and not just copy + paste it in.

    Code:
    package com.jordan.t;
    
    import android.content.Context;
    import android.graphics.Bitmap;
    import android.graphics.BitmapFactory;
    import android.graphics.Canvas;
    import android.graphics.Color;
    import android.graphics.Paint;
    import android.graphics.Paint.Align;
    import android.graphics.Typeface;
    import android.view.View;
    
    public class Main extends View {
    
    	Bitmap b1;
    	Bitmap b2;
    	Bitmap b3;
    	Typeface font;
    	
    	public Main(Context context) {
    		super(context);
    		b1 = BitmapFactory.decodeResource(getResources(), R.drawable.blackwool);
    		b2 = BitmapFactory.decodeResource(getResources(), R.drawable.bluewool);
    		b3 = BitmapFactory.decodeResource(getResources(), R.drawable.brownwool);
    		font = Typeface.createFromAsset(context.getAssets(), "G-Unit.TTF");
    	}
    
    	@Override
    	protected void onDraw(Canvas canvas) {
    		super.onDraw(canvas);
    		canvas.drawColor(Color.WHITE);
    		
    		Paint textPaint = new Paint();
    		textPaint.setARGB(50, 254, 10, 50);
    		textPaint.setTextAlign(Align.LEFT);
    		textPaint.setTextSize(30);
    		textPaint.setTypeface(font);
    		canvas.drawText("Black Wool", 0, 30, textPaint);
    		canvas.drawText("Blue Wool", 0, 280, textPaint);
    		canvas.drawText("Blue Wool", 0, 520, textPaint);
    		canvas.drawBitmap(b1, 0, 50, null);
    		canvas.drawBitmap(b2, 0, 290, null);
    		canvas.drawBitmap(b3, 0, 530, null);
    		invalidate();
    	}
    }

  • #2
    New Coder
    Join Date
    Jul 2011
    Posts
    44
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Just wondering is this supposed to be here because it's been a few days loads of views but no comments . Is there a android section that I missed because I did not see one.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •