JdV Active Member Licensed User Longtime User Jul 17, 2013 #1 Hello I'm having a problem trying to resize some views that are on a ScrollView within a TabHost panel: I created a TabHost which is the same width as Activity.width. I use AddTab2 to add a scrollview to the tab. I have two buttons in the scroll view that are on the same line Each button should be 50% of the panel's width If I size the buttons in code or using the Designer Scripts the button on the right loses about 8 pixels off the edge of the screen Is there a neat way the Designer Scripts or code can be used to ensure this doesn't happen (obviously apart from making each button 50%x-4dip)? The panel's width seems to be "-1" which makes it difficult! Regards Joe
Hello I'm having a problem trying to resize some views that are on a ScrollView within a TabHost panel: I created a TabHost which is the same width as Activity.width. I use AddTab2 to add a scrollview to the tab. I have two buttons in the scroll view that are on the same line Each button should be 50% of the panel's width If I size the buttons in code or using the Designer Scripts the button on the right loses about 8 pixels off the edge of the screen Is there a neat way the Designer Scripts or code can be used to ensure this doesn't happen (obviously apart from making each button 50%x-4dip)? The panel's width seems to be "-1" which makes it difficult! Regards Joe
PenguinHero Member Licensed User Longtime User Jul 17, 2013 #2 Hi JdV, I'm not sure if this helps, but... if I read the above correctly it sounds like you are talking about the panel for the TabHost, when the scrollview has a panel of its own doesn't it? And you want to put the buttons on the scroll view not the TabHost? Upvote 0
Hi JdV, I'm not sure if this helps, but... if I read the above correctly it sounds like you are talking about the panel for the TabHost, when the scrollview has a panel of its own doesn't it? And you want to put the buttons on the scroll view not the TabHost?
JdV Active Member Licensed User Longtime User Jul 17, 2013 #3 That's correct. The buttons should be on the ScrollView. Upvote 0
Erel B4X founder Staff member Licensed User Longtime User Jul 17, 2013 #4 Can you post a screen shot and also the designer script code? Upvote 0
JdV Active Member Licensed User Longtime User Jul 17, 2013 #5 The attached example shows where the ScrollView's panel's width is being reported as "-1". The buttons' width is set to half of the panel's width and they don't appear. Attachments Buttons.zip Buttons.zip 7 KB · Views: 352 Upvote 0
The attached example shows where the ScrollView's panel's width is being reported as "-1". The buttons' width is set to half of the panel's width and they don't appear.
PenguinHero Member Licensed User Longtime User Jul 18, 2013 #6 Hi JdV, I had a look at your example, and added a single line of code above one of your lines (shown below), to set the panel width. It now appears to work as I would expect it to. Have a look. You may need to adjust the source of the width to something else, but I'll leave that to you. Code: Copy MyScrollView.Panel.Width = MyTabHost.Width MyScrollView.Panel.LoadLayout("buttons") Let me know if this fixes it or not. PH. Upvote 0
Hi JdV, I had a look at your example, and added a single line of code above one of your lines (shown below), to set the panel width. It now appears to work as I would expect it to. Have a look. You may need to adjust the source of the width to something else, but I'll leave that to you. Code: Copy MyScrollView.Panel.Width = MyTabHost.Width MyScrollView.Panel.LoadLayout("buttons") Let me know if this fixes it or not. PH.
JdV Active Member Licensed User Longtime User Jul 18, 2013 #7 PH This hasn't fixed the issue for me - I've tried it on an emulator running Android 2.2 with a resolution of 320x480 and a Samsung phone running Android 2.2.1 at a resolution of 240x320. As you can see from the picture the button on the right is clipped slightly. (I've set MyTabHost.Color to red and MyScrollView.Panel.Color to transparent to illustrate it better). It's as if I need to set the MyScrollView.Panel.Width to MyTabHost.Width minus whatever the padding is around each tab. Thanks for your help. Regards Joe Attachments Button Screen.png 8.4 KB · Views: 559 Upvote 0
PH This hasn't fixed the issue for me - I've tried it on an emulator running Android 2.2 with a resolution of 320x480 and a Samsung phone running Android 2.2.1 at a resolution of 240x320. As you can see from the picture the button on the right is clipped slightly. (I've set MyTabHost.Color to red and MyScrollView.Panel.Color to transparent to illustrate it better). It's as if I need to set the MyScrollView.Panel.Width to MyTabHost.Width minus whatever the padding is around each tab. Thanks for your help. Regards Joe
Erel B4X founder Staff member Licensed User Longtime User Jul 19, 2013 #8 The width reported is -1 because this is the value of the FILL_PARENT constant. You can create a simple layout file with only the ScrollView and with this code: Code: Copy MyScrollView.SetLeftAndRight(0, 100%x) MyScrollView.SetTopAndBottom(0, 100%y) Also set the buttons position with the designer: Code: Copy AutoScaleAll ButtonLeft.SetLeftAndRight(0, 50%x) ButtonRight.SetLeftAndRight(50%x, 100%x) Your program code should be: Code: Copy Activity.Initialize("") MyTabHost.Initialize("") Activity.AddView(MyTabHost, 0, 0, Activity.Width, Activity.Height) MyTabHost.AddTab("Tab 1", "1") 'this is the layout file with the scroll view. MyScrollView.Panel.LoadLayout("buttons") Upvote 0
The width reported is -1 because this is the value of the FILL_PARENT constant. You can create a simple layout file with only the ScrollView and with this code: Code: Copy MyScrollView.SetLeftAndRight(0, 100%x) MyScrollView.SetTopAndBottom(0, 100%y) Also set the buttons position with the designer: Code: Copy AutoScaleAll ButtonLeft.SetLeftAndRight(0, 50%x) ButtonRight.SetLeftAndRight(50%x, 100%x) Your program code should be: Code: Copy Activity.Initialize("") MyTabHost.Initialize("") Activity.AddView(MyTabHost, 0, 0, Activity.Width, Activity.Height) MyTabHost.AddTab("Tab 1", "1") 'this is the layout file with the scroll view. MyScrollView.Panel.LoadLayout("buttons")
JdV Active Member Licensed User Longtime User Jul 19, 2013 #9 Perfect! That's exactly what I wanted. Thanks all for your help. Joe Upvote 0
JdV Active Member Licensed User Longtime User Jul 27, 2013 #10 I have a further issue with TabHost panels. Please see the attached example. When the on-screen keyboard is visible the TabHost looks like it is being resized correctly. However the ScrollView.Panel.Height no longer appears to be large enough to allow all of the buttons and fields to be seen. What should the ScrollView.Panel.Height be set to when the TabHost is resized? Or is there a better way of reacting to the appearance of the keyboard? Joe Attachments TabHostDemo2.zip TabHostDemo2.zip 8.7 KB · Views: 351 Upvote 0
I have a further issue with TabHost panels. Please see the attached example. When the on-screen keyboard is visible the TabHost looks like it is being resized correctly. However the ScrollView.Panel.Height no longer appears to be large enough to allow all of the buttons and fields to be seen. What should the ScrollView.Panel.Height be set to when the TabHost is resized? Or is there a better way of reacting to the appearance of the keyboard? Joe
Erel B4X founder Staff member Licensed User Longtime User Jul 28, 2013 #11 Try this: Code: Copy Sub IME_HeightChanged(NewHeight As Int, OldHeight As Int) Dim w = MyScrollView.Width, h = MyScrollView.Height + NewHeight - OldHeight As Int MyTabHost.Height = NewHeight Activity.RerunDesignerScript("1", w, h) End Sub Upvote 0
Try this: Code: Copy Sub IME_HeightChanged(NewHeight As Int, OldHeight As Int) Dim w = MyScrollView.Width, h = MyScrollView.Height + NewHeight - OldHeight As Int MyTabHost.Height = NewHeight Activity.RerunDesignerScript("1", w, h) End Sub
JdV Active Member Licensed User Longtime User Jul 30, 2013 #12 That does the trick - though I won't pretend I understand how it works! If I want to display a banner advert at the bottom of the screen I place the TabHost on the Activity like this: Code: Copy Activity.AddView(MyTabHost, 0, 0, Activity.Width, Activity.Height - 50dip) However, when the keyboard appears the ScrollView is 50dip too short. I modified the IME_HeightChanged sub as shown below: Code: Copy Sub IME_HeightChanged(NewHeight As Int, OldHeight As Int) Dim w = MyScrollView.Width, h = MyScrollView.Height + NewHeight - OldHeight As Int If NewHeight = Activity.Height Then MyTabHost.Height = NewHeight-50dip Else MyTabHost.Height = NewHeight End If Activity.RerunDesignerScript("1", w, h) End Sub I realise I'm probably missing something obvious but please point it out! Upvote 0
That does the trick - though I won't pretend I understand how it works! If I want to display a banner advert at the bottom of the screen I place the TabHost on the Activity like this: Code: Copy Activity.AddView(MyTabHost, 0, 0, Activity.Width, Activity.Height - 50dip) However, when the keyboard appears the ScrollView is 50dip too short. I modified the IME_HeightChanged sub as shown below: Code: Copy Sub IME_HeightChanged(NewHeight As Int, OldHeight As Int) Dim w = MyScrollView.Width, h = MyScrollView.Height + NewHeight - OldHeight As Int If NewHeight = Activity.Height Then MyTabHost.Height = NewHeight-50dip Else MyTabHost.Height = NewHeight End If Activity.RerunDesignerScript("1", w, h) End Sub I realise I'm probably missing something obvious but please point it out!
Erel B4X founder Staff member Licensed User Longtime User Jul 31, 2013 #13 I think that MyTabHost.Height should always be NewHeight - 50dip. Upvote 0
JdV Active Member Licensed User Longtime User Jul 31, 2013 #14 I don't need to leave a 50dip gap between the keypad and MyTabHost when the keypad is visible. I'm just struggling to make the whole layout work when the keypad appears and is subsequently dismissed. Upvote 0
I don't need to leave a 50dip gap between the keypad and MyTabHost when the keypad is visible. I'm just struggling to make the whole layout work when the keypad appears and is subsequently dismissed.
Erel B4X founder Staff member Licensed User Longtime User Aug 1, 2013 #15 Can you upload the complete project (File - Export as zip)? Upvote 0
JdV Active Member Licensed User Longtime User Aug 1, 2013 #16 Attached as requested. Attachments TabHostDemo2.zip TabHostDemo2.zip 8.8 KB · Views: 335 Upvote 0
Erel B4X founder Staff member Licensed User Longtime User Aug 2, 2013 #17 Change the code to: Code: Copy If NewHeight = Activity.Height Then MyTabHost.Height = NewHeight-50dip Else MyTabHost.Height = NewHeight h = h + 50dip End If You will also need to change the ScrollPosition to make the EditText visible. Upvote 0
Change the code to: Code: Copy If NewHeight = Activity.Height Then MyTabHost.Height = NewHeight-50dip Else MyTabHost.Height = NewHeight h = h + 50dip End If You will also need to change the ScrollPosition to make the EditText visible.