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.

Results 1 to 7 of 7

Thread: Drawing and Scrolling

  1. #1
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,707
    Thanks
    25
    Thanked 338 Times in 313 Posts

    Default Drawing and Scrolling

    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/


  2. #2
    Member
    Join Date
    Mar 2012
    Location
    United States
    Posts
    118
    My Mood
    Inspired
    Thanks
    1
    Thanked 33 Times in 31 Posts

    Default Re: Drawing and Scrolling

    EDIT:
    Sorry about that, wasn't paying attention.
    Last edited by KucerakJM; July 19th, 2014 at 05:24 PM.

  3. #3
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    897
    Thanks
    0
    Thanked 166 Times in 148 Posts

    Default Re: Drawing and Scrolling

    Quote Originally Posted by KucerakJM View Post
    This is in the android sub-forum. These tutorials are not going to help the OP one bit.

  4. #4
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,707
    Thanks
    25
    Thanked 338 Times in 313 Posts

    Default Re: Drawing and Scrolling

    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/

  5. #5
    Forum VIP
    Join Date
    Jun 2011
    Posts
    392
    My Mood
    Busy
    Thanks
    49
    Thanked 112 Times in 95 Posts
    Blog Entries
    5

    Default Re: Drawing and Scrolling

    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

  6. #6
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,707
    Thanks
    25
    Thanked 338 Times in 313 Posts

    Default Re: Drawing and Scrolling

    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/

  7. #7
    Forum VIP
    Join Date
    Jun 2011
    Posts
    392
    My Mood
    Busy
    Thanks
    49
    Thanked 112 Times in 95 Posts
    Blog Entries
    5

    Default Re: Drawing and Scrolling

    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.

Similar Threads

  1. netbeans crazy scrolling behaviour
    By startas in forum Java IDEs
    Replies: 7
    Last Post: January 29th, 2014, 09:43 AM
  2. code with problem in layout and scrolling
    By Man1 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 3rd, 2013, 05:23 AM
  3. [SOLVED] JScrollPane and programatic scrolling
    By brajan1984 in forum AWT / Java Swing
    Replies: 6
    Last Post: January 6th, 2013, 02:58 PM
  4. scrolling in jsp tables
    By ravindraneeluri in forum Member Introductions
    Replies: 1
    Last Post: May 25th, 2011, 10:17 AM
  5. Clipping while scrolling
    By copeg in forum AWT / Java Swing
    Replies: 0
    Last Post: May 24th, 2010, 10:37 PM