Android Question Regarding ScrollView

shashkiranr

Active Member
Licensed User
Longtime User
I know there has been many posts about this but i always get it wrong so i want to ask few questions regarding scrollview.


1. Is it good to add scrollview through a designer or through the code.

2. Incase we are load layout from scrollview.panel.layout() , How to set the scrollview height so that it occupies all the contents in the layout.

I am adding a scrollview to the activity and then loading a layout by calling scrollview.panel.layout() but i am not able to set the height of the scrollview properly when device is in landscape mode.

here is the code
B4X:
#Region  Project Attributes
    #ApplicationLabel:    FPAC Manager
    #VersionCode: 1
    #VersionName: Demo
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim WRAP_WIDTH As Int    : WRAP_WIDTH = -2
    Dim WRAP_HEIGHT As Int    : WRAP_HEIGHT = -2
    Dim Main_Text_Size As Int    : Main_Text_Size = 20
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
   
    'Settings Layout Variables
    Dim ActivityLabel As Label
    Dim ActivitySpinner As Spinner
    Dim CriticalButton As Switch
    Dim CriticalLabel As Label
    Dim DividerPanel As Panel
    Dim EquipLabel As Label
    Dim EquipSpinner As Spinner
    Dim HighRButton As RadioButton
    Dim LowRButton As RadioButton
    Dim MainModeLabel As Label
    Dim MedRButton As RadioButton
    Dim ProjectLabel As Label
    Dim ProjectSpinner As Spinner
    Dim PunchListButton As Switch
    Dim PunchListLabel As Label
    Dim RiskLabel As Label
    Dim SafetyButton As Switch
    Dim SafetyLabel As Label
    Dim SettingsMain As Panel
    Dim MainModButton As Switch
   
   
    Dim MainScrollView As ScrollView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:

    MainScrollView.Initialize(1000dip)
    Activity.AddView(MainScrollView,0,0,100%x,100%y)
    MainScrollView.Panel.LoadLayout("Settings")

    Set_Text
    Resize_Labels
    

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Set_Text
    ActivityLabel.Text = "Activity"
    ActivityLabel.TextSize = Main_Text_Size
   
    ProjectLabel.Text = "Project"
    ProjectLabel.TextSize = Main_Text_Size
   
    EquipLabel.Text = "Equip."
    EquipLabel.TextSize = Main_Text_Size
   
    MainModeLabel.Text = "Maintainence Mode"
    MainModeLabel.TextSize = Main_Text_Size
   
    SafetyLabel.Text = "Safety Complaince"
    SafetyLabel.TextSize = Main_Text_Size
   
    PunchListLabel.Text = "Punch List Inclusion"
    PunchListLabel.TextSize = Main_Text_Size
   
    CriticalLabel.Text = "Critical Condition"
    CriticalLabel.TextSize = Main_Text_Size
   
    RiskLabel.Text = "Risk"
    RiskLabel.TextSize = Main_Text_Size
   
    LowRButton.Text = "Low"
    LowRButton.TextSize = Main_Text_Size
   
    MedRButton.Text = "Med"
    MedRButton.TextSize = Main_Text_Size
   
    HighRButton.Text = "High"
    HighRButton.TextSize = Main_Text_Size
End Sub

Sub Resize_Labels
    ActivityLabel.Width = WRAP_WIDTH
    ActivityLabel.Height = WRAP_HEIGHT
   
    ProjectLabel.Width = WRAP_WIDTH
    ProjectLabel.Height = WRAP_HEIGHT
   
    EquipLabel.Width = WRAP_WIDTH
    EquipLabel.Height = WRAP_HEIGHT
   
    MainModeLabel.Width = WRAP_WIDTH
    MainModeLabel.Height = WRAP_HEIGHT
   
   
    SafetyLabel.Width = WRAP_WIDTH
    SafetyLabel.Height = WRAP_HEIGHT
   
    PunchListLabel.Width = WRAP_WIDTH
    PunchListLabel.Height = WRAP_HEIGHT
   
    CriticalLabel.Width = WRAP_WIDTH
    CriticalLabel.Height = WRAP_HEIGHT
   
    RiskLabel.Width = WRAP_WIDTH
    RiskLabel.Height = WRAP_HEIGHT
   
    LowRButton.Width = WRAP_WIDTH
    LowRButton.Height = WRAP_HEIGHT
   
    MedRButton.Width = WRAP_WIDTH
    MedRButton.Height = WRAP_HEIGHT
   
    HighRButton.Width = WRAP_WIDTH
    HighRButton.Height = WRAP_HEIGHT
End Sub

In the layout there is a SettingsMain panel which contain all the labels and buttons mentioned in the code.

I tried to set the scrollview panel height to SettingsMain panel height but it dint work

B4X:
MainScrollView.Panel.Height = SettingsMain.Height

Kindly let me know the mistake i am making here.

Regards,
SK
 

klaus

Expert
Licensed User
Longtime User
Why are you setting all views width and height ot -2, even the Buttons ?
If the height changes you could have trouble with views overlapping each other because you don't adapt the Top property.
It the text is too long a view could become wider than the parent view.

So what exactly do you want to do ?
You say it doesn't work, what doesn't work.
Where did you set MainScrollView.Panel.Height = SettingsMain.Height ?

This code should work if there is no height change in the Resize_Labels routine.
B4X:
MainScrollView.Initialize(1000dip)
Activity.AddView(MainScrollView,0,0,100%x,100%y)
MainScrollView.Panel.LoadLayout("Settings")

MainScrollView.Panel.Height = SettingsMain.Height
' DoEvents
If it doesn't work remove the ' from the DoEvents line.

Best regards.
 
Upvote 0

shashkiranr

Active Member
Licensed User
Longtime User
Thanks Klaus,

i removed the resize_labels sub. yes it complicates when you use -2 value. Now i am getting the scrollview but its scrolling too much i mean it is not stopping where the settings panel ends.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
It's difficult to help without seeing the whole code.
Couldn't you post your project as a zip file (IDE menu File / Export As Zip) or at least a smaller one showing the problem so we could see what you have done and test it in the same conditions as you do.

Best regards.
 
Upvote 0

shashkiranr

Active Member
Licensed User
Longtime User
Hi Kluas,

Sorry for the delay here is the sample test. I am getting the scrollview both in portrait and landscape but not able to set the height.

Kindly guide me in this.

Regards,
SK
 

Attachments

  • testt.zip
    8.5 KB · Views: 212
Upvote 0

klaus

Expert
Licensed User
Longtime User
I'm afraid that you are confusing MainScrollView, SettingsMain and MainScrollView.Panel !

MainScrollView occupies the whole screen which is what you want.
SettingsMain panel holds all your views and is copied onto MainScrollView.Panel which is the internal panel of the ScrollView.
In the DesignerScripts you set SettingsMain.SetTopAndBottom(0,100%y) which gives SettingsMain.Height = 100%y.
If you are in landscape orientation SettingsMain.Height is bigger than the screen height but you limit it in setting SettingsMain.Height = 100%y and therefor you have no scrolling !

Best regards.
 
Upvote 0

shashkiranr

Active Member
Licensed User
Longtime User
Hi Klaus,

Here is one more layout which i have created. The panel is bigger than the screen. The problem is, it is not showing all the labels in it.
I even tested in a 10" Tab but still it is not showing .

Kindly let me know the mistake i am making here.

I have attached the project for your reference.

Regards,
SK
 

Attachments

  • testt.zip
    9.6 KB · Views: 197
Upvote 0

klaus

Expert
Licensed User
Longtime User
If the height of the panel is smaller than the screen there is of course no scrolling !
You height calculation is wrong you dont take into account the space between the views.
You can calculate it simply with:
CreateActivityPanel.Height = CriticalButton.Top + CriticalButton.Height + 5dip

With the height calculation above the ScrollView scrolls on my Nexus One, panel height heigher than the screen height, and doen't scroll on my Asus TF700 tablet, panel height smaller than the screen height.

I don't really understand your logic.
You have a layout with a layout variant of 320 * 480 scale 160.
The panel holding the views has a width of 800, the views are not shown like.
Then you position the views in the DesignerScripts.
Then you change the text size and the text in the code.

What device or screen size your project is supposed to work on ?
Why don't you define everything in the Designer ?
Define a default layout, use AutoScale and fine adjust the views in the DesignerScripts.
Or use layout with a variant matching the screen size if the program is dedicated for one device type.
Set the texts in the Designer and the text size in the DesignerScripts, you can define variables in the DesignerScripts.

Attached a modified version.

Best regards.
 

Attachments

  • testt1.zip
    9.6 KB · Views: 210
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…