Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-23-2012, 01:07 AM   PM User | #1
jordandap
New Coder

 
Join Date: Jul 2011
Posts: 44
Thanks: 5
Thanked 0 Times in 0 Posts
jordandap is an unknown quantity at this point
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();
	}
}
jordandap is offline   Reply With Quote
Old 06-24-2012, 02:32 AM   PM User | #2
jordandap
New Coder

 
Join Date: Jul 2011
Posts: 44
Thanks: 5
Thanked 0 Times in 0 Posts
jordandap is an unknown quantity at this point
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.
jordandap is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:14 PM.


Advertisement
Log in to turn off these ads.