Android Tutorial ScrollView example with a Panel higher than the screen

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.
 

Attachments

  • ScrollViewBigPanel1.jpg
    ScrollViewBigPanel1.jpg
    18.3 KB · Views: 23,048
  • ScrollViewBigPanel2.jpg
    ScrollViewBigPanel2.jpg
    28.6 KB · Views: 22,119
  • ScrollViewBigPanel.zip
    8.8 KB · Views: 1,316
Last edited:

Gary Miyakawa

Active Member
Licensed User
Longtime 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
 

SteveBee

Member
Licensed User
Longtime 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
 

Lon

Member
Licensed User
Longtime 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?
 

Lon

Member
Licensed User
Longtime 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?
 

klaus

Expert
Licensed User
Longtime User
With this line :
B4X:
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.
 

Lon

Member
Licensed User
Longtime 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:
 

Lon

Member
Licensed User
Longtime 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:

baron159

Member
Licensed User
Longtime 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?
 

klaus

Expert
Licensed User
Longtime 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.
 

baron159

Member
Licensed User
Longtime 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?
 

baron159

Member
Licensed User
Longtime 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?
 

BarrySumpter

Active Member
Licensed User
Longtime User
Do I have to have a Designer Layout?
If not, how can I assign the scroll view panel?

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

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

And don't forget:
B4X:
        ScrollView1.Panel.Height = 1000dip
 
Last edited:

Darren69

Member
Licensed User
Longtime 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
 
Top