Android Question struggling with scrollview

Kris Wold

New Member
Hi all,

First post to the community and have searched hi and low for the answer (I promise - but do shame me if I have missed the answer!)

I am trying to handle the screen layout when the keyboard is active, so the screen would essentially push of the top of the screen until the keyboard has been closed or input entry is completed.

With the help from this forum I have concluded a scrollview object was the way forward. i have added the scroll view and load the layout into it but even though i have set the vertical anchors to be fluid (not sure if that is the right phrase, but set so it stretches with the screen) it condenses my layout as if the keyboard is open and also overlays a lot of my text fields and buttons.

Anyway, this community is fantastic and the product has really been an amazing find for me (access developer who was struggling with the learning curve of mobile app development)

Thanks all, look forward to the replies, suggestions or telling off's.

Kris Wold
 

Attachments

  • screenshot.jpg
    screenshot.jpg
    14.5 KB · Views: 287

Brian Dean

Well-Known Member
Licensed User
Longtime User
Handling the keyboard is often awkward, and it is difficult to automate. When the keyboard opens the Activity dimensions do not change (I think), so anchors might not help. There is a keyboard event which you can use to adapt the height of your scroll view ...

B4X:
Private Sub IME_HeightChanged (NewHeight As Int, OldHeight As Int)
    If (NewHeight < OldHeight) Then                    ' Keyboard is open
        scrBase.SetLayout(0, 0, Activity.Width, NewHeight)
        scrBase.ScrollPosition = inputView - NewHeight
    Else                           ' Reset scrollview height
        scrBase.SetLayout(0, 0, Activity.Width, Activity.Height)
    End If
End Sub

This code resizes the scrollview so that it fits on the visible screen, and then changes the scroll position to ensure that a particular view (the target input EditText, for example) is in the visible portion of the scroll view. If you are not sure which input view the User is aiming for then at least they can manually scroll until it is visible. Hope this moves you forward.
 
Upvote 0

Kris Wold

New Member
Don't use ScrollView at all.

Use xCustomListView. Easier to work with and cross platform.

In your case you should check B4XPreferencesDialog as it will save you a lot of work.

Thank's Erel.

I have had a look at B4XPreferencesDialog, and it is a very powerful tool and will be useful in the future. although I only found examples and tutorials in which the dialog is a dialog, rather than a full screen activity.

I was hoping for a simple workaround but fear I may need to start over layout wise from the ground up. in regards to xCustomListView;

maybe this is where I have gone so wrong tbh!! is xCustomListView also known just as CustomListView? as I have been unable to figure out how to load a full layout to it, if it is not please could you attach the library for me

And finally, could you offer some guidance for best practice as to layouts? I need the app to respond to the keyboard, not by dynamically resizing fields but by making sure the current scroll position at the bottom of the screen is kept when the keyboard appears.

If this is not currently possible, or simply just out of my abilities at present that's fine and something i will have to live with.

Thanks for your support, and this powerful platform you have shared with us all.
 
Upvote 0

Kris Wold

New Member
Handling the keyboard is often awkward, and it is difficult to automate. When the keyboard opens the Activity dimensions do not change (I think), so anchors might not help. There is a keyboard event which you can use to adapt the height of your scroll view ...

B4X:
Private Sub IME_HeightChanged (NewHeight As Int, OldHeight As Int)
    If (NewHeight < OldHeight) Then                    ' Keyboard is open
        scrBase.SetLayout(0, 0, Activity.Width, NewHeight)
        scrBase.ScrollPosition = inputView - NewHeight
    Else                           ' Reset scrollview height
        scrBase.SetLayout(0, 0, Activity.Width, Activity.Height)
    End If
End Sub

This code resizes the scrollview so that it fits on the visible screen, and then changes the scroll position to ensure that a particular view (the target input EditText, for example) is in the visible portion of the scroll view. If you are not sure which input view the User is aiming for then at least they can manually scroll until it is visible. Hope this moves you forward.


Hi Brian,

Thanks for this code snippit, unfortunately out of the box it didn't fire, i searched and found some IME help articles but have only succeeded to be able to fire the function manually and not via keyboard up. unfortunately i am unable to share my app as i am looking at live data. I understand seeing the code makes the process so much easier.

Again,

Thanks so much for taking the time to help me. it really is appreciated.
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
... unfortunately out of the box it didn't fire,

I have made this mistake myself. You need to include this line of code ...

B4X:
IME.AddHeightChangedEvent

I told you that using IME was awkward!
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
is xCustomListView also known just as CustomListView?

Yes.

please could you attach the library for me

The xCustomListView library is packaged with the B4A app. (current version 1.72 if you are using the latest b4a version 9.80)

Just reference / check the lib in your app & add a CustomView (CustomListView) to a layout.
Create a second layout with all your CLV views . This layout is loaded to a panel in the CreatListItem sub ( as per Example )...

See this thread for more info and also extensions that might be of interest depending on your layout.

Here is a xCLV Example ... from that thread ... it will show how to load a simple layout.

Just open a new thread for any problems you are having.
 
Upvote 0
Top