I need to create a view which basically just consists of drawing and the ability for the user to scroll the drawing.
Does anyone know of any good tutorials which cover this?
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
I need to create a view which basically just consists of drawing and the ability for the user to scroll the drawing.
Does anyone know of any good tutorials which cover this?
NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:
When asking for help, please follow these guidelines to receive better and more prompt help:
1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
2. Give full details of errors and provide us with as much information about the situation as possible.
3. Give us an example of what the output should look like when done correctly.
Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/
EDIT:
Sorry about that, wasn't paying attention.
Last edited by KucerakJM; July 19th, 2014 at 04:24 PM.
FYI: so I have figured out the drawing stuff.
However I am still trying to figure out the scrolling. I think what I'm looking for is panning, not scrolling.
I have a view and an activity. The limits of the view is greater than the size of the screen, so the user needs the ability to pan the view. Any suggestions?
NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:
When asking for help, please follow these guidelines to receive better and more prompt help:
1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
2. Give full details of errors and provide us with as much information about the situation as possible.
3. Give us an example of what the output should look like when done correctly.
Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/
It kinda depends on what you are trying to achieve. If it's just UI elements you should be able to get away with wrapping it up with a ScrollView in the layout xml. ScrollViews are the easiest (near trivial) way of handling a screen that doesn't fit the content so try this out first.
If you've got a canvas (I'm assuming you do because of the already solved drawing part) you could take a look at creating a custom OnTouchListener implementation. Note you can't apply an onTouchListener to the canvas itself because it isn't a subclass of a View. It will have to go on the view that contains it.
Here is an excellent example of an OnTouchListener
My current plan for panning is to shift all the graphics and redraw everything. But that seems extremely memory intensive (I could only draw what is visible I suppose). I was hoping to see if there was a way to move about the already drawn graphics.
NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:
When asking for help, please follow these guidelines to receive better and more prompt help:
1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
2. Give full details of errors and provide us with as much information about the situation as possible.
3. Give us an example of what the output should look like when done correctly.
Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/
If you are drawing to Bitmap you could use drawBitmap (Bitmap bitmap, Rect src, Rect dst, Paint paint). The idea is to first generate the bitmap and store it as a member variable then redraw the canvas in the OnTouchListener overrides. You are limited to a 4096x4096 texture space doing this.
Again it depends on what you are doing. My answer will be different for the background in a sidescroller game that it would be for a map overlay.