Android Tutorial ScrollView example with a Panel higher than the screen

Discussion in 'Tutorials & Examples' started by klaus, Jun 4, 2011.

  1. klaus

    klaus Expert Licensed User

    Attached you find an example with a ScrollView with a Panel higher than the screen.

    The layouts are designed in the Designer, not in the code.

    There are 2 layout files:
    - Main with the ScrollView.
    - ScrollViewLayout has one Panel higher than the screen, 7 Label views and 7 EditText views, the Panel height is set so the last EditText view is on top of the screen when the panel's lower edge is on the lower edge of the screen.

    Clicking on an EditText moves the Scrollview up to show this EditText view on top of the screen to avoid interference with the virtual keyboard.

    Best regards.
     

    Attached Files:

    Last edited: Jul 11, 2017
    edm68, Dave O, solfinker and 2 others like this.
  2. Gary Miyakawa

    Gary Miyakawa Active Member Licensed User

    Klaus,

    As always, thank you very much! I was close to doing what you built but I didn't have the scrollview in the "other(main)" layout.

    That will help me build exactly what I need!

    Thank you !

    Gary M
     
  3. SteveBee

    SteveBee Member Licensed User

    Thank you

    Klaus - great example, showing how to use 2 different layouts, with one being a 'container' for the other.

    Also the use of setting the Parent of a view.

    I was struggling with how to set up to use ScrollView for a data input form - now 'sorted'... TX
     
  4. Lon

    Lon Member Licensed User

    I am just trying out this example. But it looks like there are times when after selecting a bottom EditText the whole Activity view gets moved up off the top of the screen when the keyboard shows. The activity title bar and device status bar are no longer visible. After that happens the only way to restore scrolling to see all the view I have to hide the keyboard. Is there any way to stop that from happening?
     
  5. klaus

    klaus Expert Licensed User

    You can comment out this line:
    Code:
    '   scvTest.ScrollPosition = Send.Top - 10dip
    Best regards.
     
  6. Lon

    Lon Member Licensed User

    Thanks for your help.
    I already tried that but it does not stop the view from being shifted off the top of the screen until the keyboard is closed.
    Is this a new feature of B4A to keep the current EditText input visible or does the OS automaticaly do that?
     
  7. klaus

    klaus Expert Licensed User

    With this line :
    Code:
    scvTest.ScrollPosition = Send.Top - 10dip
    the panel is shifted up by the code.
    With this line commented out the OS does the shifting automatically.
    You can set the height of the panel pnlTest to 720 (in the Designer) then when the ScrollView shows the lowest EditText view and it gets the focus the OS moves it up when the virtual keyboard is shown and moves down when the keyboard is hidden.

    Best regards.
     
  8. Lon

    Lon Member Licensed User

    Well that's the problem. I can't scroll to view all the EditText boxes with the keyboard displayed after the OS moves the view up.:confused:
     
  9. thedesolatesoul

    thedesolatesoul Expert Licensed User

  10. Lon

    Lon Member Licensed User

    Well I'm not getting anywhere with this. I tried editing the Manifest Editor with all kinds of variations of :
    <activity android:windowSoftInputMode="stateVisible|adjustResize"/>)
    But nothing seemed to change in the way the view moved or the keyboard was displayed. I might be putting it in the wrong location.
    If I could hide the keyboard when the ScrollView was moved that would probably solve the issue but I'm reading here that one cannot do that.
    Edit:
    I needed to us: SetActivityAttribute(main, android:windowSoftInputMode,"stateVisible|adjustUnspecified")
    Seems to work fine now. :)
     
    Last edited: Feb 4, 2012
  11. baron159

    baron159 Member Licensed User

    Problem?

    I was using your code as an example and I have everything the same but when I try to test the Program. I get an error message that says I need to Initialize it. How do I do it? Or why is it happening?
     
  12. klaus

    klaus Expert Licensed User

    I tested the code from post#1, it works without any problem.
    So there must be something different in your code.
    To see what happens you need to post your project as a zip file, otherwise it's impossible to help you.

    Best regards.
     
  13. baron159

    baron159 Member Licensed User

    Re: Problem

    Sorry About not uploading it.
    Here is is
     
  14. klaus

    klaus Expert Licensed User

    You should look more carefully at the code when you try to use one.
    In the original code:
    - In the main layout file you have the ScrollView
    - In the ScrollViewLayout file you have a Panel with all the views.

    In your code:
    - In the main layout file you have a Panel and one Button
    - In the scrllview layout file you have the ScrollView.

    This means that you first load a Panel with a Button and then you try to load a layout to a ScrollView that doesn't exist !

    Best regards.
     
  15. baron159

    baron159 Member Licensed User

    Okay so I have switched them Around but i Get an srcllview.bal could not be found...

    Could you fix my code I Up loaded and reupload the correct layout Please?
     
  16. klaus

    klaus Expert Licensed User

    Here you are.

    Best regards.
     

    Attached Files:

    Vahid.m likes this.
  17. baron159

    baron159 Member Licensed User

    Thank You so much I can start making my program finally. Ha Ha

    But I do have one more quick question.

    Can I have a Horizontal Scroll View working with a regular Scroll View?
    Or am I asking for too much?
     
  18. klaus

    klaus Expert Licensed User

    No, you can't. You can use either a vertical ScrollView or a HorizonzalScrollView but not two combined.

    Best regards.
     
  19. BarrySumpter

    BarrySumpter Active Member Licensed User

    Do I have to have a Designer Layout?
    If not, how can I assign the scroll view panel?

    Code:
    ...
    scvTest.Panel.LoadLayout(
    "ScrollViewLayout")
    ...
    grrrr, Soon as I post I find it:

    Code:
    ScrollView1.Panel.AddView(...)
    And, well, Duh!

    And don't forget:
    Code:
    ScrollView1.Panel.Height = 1000dip
     
    Last edited: Aug 21, 2012
  20. Darren69

    Darren69 Member Licensed User

    Hello there,

    is there a trick to getting a scrollview to work with designer scripts?

    if I use a designer script to place my buttons and edit fields where I want them all I see is a blank Panel View that will scroll.

    if I delete all the code in the designer script then it works, but the buttons and editfields don't look as nice when I switch between devices.

    I am sure I have overlooked something but any help would be appreciated.

    thanks
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice