Computersmith64 Well-Known Member Licensed User Longtime User Dec 11, 2013 #1 Well, I'm stumped... I have a layout containing a bunch of Labels, EditTexts, a Panel for showing a camera preview & the photo taken, & 3 buttons. In my Activity_Create, if I create & initialize a ScrollView & then load the layout into the ScrollView.Panel, everything works fine. Here is the code: Code: Copy Sub Activity_Create(FirstTime As Boolean) vScroll.Initialize(100dip) Activity.AddView(vScroll, 0, 0, 100%x, 100%y) vScroll.Panel.LoadLayout("details") vScroll.Panel.Height = pnlDetails.Height End Sub The attached image - Works (Small).png - shows the result. However, if I load another layout that contains a TabHost, then create & initialize the ScrollView & then add the first layout to the ScrollView, then create a tab containing the ScrollView, things don't go so well. I end up with most of the layout, however the panel for the photo displays a bunch of colored lined (instead of the photo) & one of the 3 buttons is missing. Here is the code: Code: Copy Sub Activity_Create(FirstTime As Boolean) Activity.LoadLayout("th") vScroll.Initialize(100dip) tabDetails.AddTab2("Pet Details", vScroll) vScroll.Panel.LoadLayout("details") vScroll.Panel.Height = pnlDetails.Height End Sub The attached image - Fails.png - shows the result. I've tried all kinds of different orders of the code, tried creating the TabHost in code (instead of loading it from a layout) & I don't know how many other connotations, but I cannot get it to display the photo Panel properly or show the 3rd button. Any ideas? Thanks - Colin. Attachments Works (Small).png 451.5 KB · Views: 569 Fails.png 68.1 KB · Views: 580
Well, I'm stumped... I have a layout containing a bunch of Labels, EditTexts, a Panel for showing a camera preview & the photo taken, & 3 buttons. In my Activity_Create, if I create & initialize a ScrollView & then load the layout into the ScrollView.Panel, everything works fine. Here is the code: Code: Copy Sub Activity_Create(FirstTime As Boolean) vScroll.Initialize(100dip) Activity.AddView(vScroll, 0, 0, 100%x, 100%y) vScroll.Panel.LoadLayout("details") vScroll.Panel.Height = pnlDetails.Height End Sub The attached image - Works (Small).png - shows the result. However, if I load another layout that contains a TabHost, then create & initialize the ScrollView & then add the first layout to the ScrollView, then create a tab containing the ScrollView, things don't go so well. I end up with most of the layout, however the panel for the photo displays a bunch of colored lined (instead of the photo) & one of the 3 buttons is missing. Here is the code: Code: Copy Sub Activity_Create(FirstTime As Boolean) Activity.LoadLayout("th") vScroll.Initialize(100dip) tabDetails.AddTab2("Pet Details", vScroll) vScroll.Panel.LoadLayout("details") vScroll.Panel.Height = pnlDetails.Height End Sub The attached image - Fails.png - shows the result. I've tried all kinds of different orders of the code, tried creating the TabHost in code (instead of loading it from a layout) & I don't know how many other connotations, but I cannot get it to display the photo Panel properly or show the 3rd button. Any ideas? Thanks - Colin.
Erel B4X founder Staff member Licensed User Longtime User Dec 11, 2013 #2 Check the width and height of the Panel before the call to Camera.Initialize. Upvote 0
Computersmith64 Well-Known Member Licensed User Longtime User Dec 11, 2013 #3 Thanks Erel - I thought the same thing when I was looking at the screen shots again last night in bed. So this morning I ran the debugger & found that for some strange reason the panel that my layout sits on gets set to a width of -1 when it gets loaded into the tabhost. I resized the photo panel & also reset the left position of the button that was missing (turns out there were 2 buttons missing under certain circumstances) & it fixed the problem - albeit that it seems like the TabHost is wider than the Activity.Width, because to get the right side of the views to line up at -5dip of the display, I actually have to subtract -25dip. So instead of manually changing the widths & positions of the views, I thought I would just run Activity.RerunDesignerScript - but then I ran into the same issue that I have seen pretty much every time I try to use SetLayout - which is this error: "java.lang.RuntimeException: java.lang.RuntimeException: java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to anywheresoftware.b4a.BALayout$LayoutParams" I'm not even sure that rerunning the designer script will give me what I want, but it seems more efficient than having to reset the positions of multiple views manually after the layout is loaded into the TabHost. Thanks - Colin. Upvote 0
Thanks Erel - I thought the same thing when I was looking at the screen shots again last night in bed. So this morning I ran the debugger & found that for some strange reason the panel that my layout sits on gets set to a width of -1 when it gets loaded into the tabhost. I resized the photo panel & also reset the left position of the button that was missing (turns out there were 2 buttons missing under certain circumstances) & it fixed the problem - albeit that it seems like the TabHost is wider than the Activity.Width, because to get the right side of the views to line up at -5dip of the display, I actually have to subtract -25dip. So instead of manually changing the widths & positions of the views, I thought I would just run Activity.RerunDesignerScript - but then I ran into the same issue that I have seen pretty much every time I try to use SetLayout - which is this error: "java.lang.RuntimeException: java.lang.RuntimeException: java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to anywheresoftware.b4a.BALayout$LayoutParams" I'm not even sure that rerunning the designer script will give me what I want, but it seems more efficient than having to reset the positions of multiple views manually after the layout is loaded into the TabHost. Thanks - Colin.
Erel B4X founder Staff member Licensed User Longtime User Dec 11, 2013 #4 You should create a simple layout file with this panel and add it with AddTab instead of AddTab2. Call Panel.SetLeftAndRight(0, 100%x) and Panel.SetTopAndBottom(0, 100%y) in the designer script. Upvote 0
You should create a simple layout file with this panel and add it with AddTab instead of AddTab2. Call Panel.SetLeftAndRight(0, 100%x) and Panel.SetTopAndBottom(0, 100%y) in the designer script.
Computersmith64 Well-Known Member Licensed User Longtime User Dec 11, 2013 #5 I'm not sure I understand Erel. Do you mean the panel that shows the photo/preview? The layout is already on a panel (pnlDetails) & it's being set as you suggest in the designer script. Can you explain why I'm getting the casting error when I try to resize a view using SetLayout or when I try to rerun the designer script? Thanks - Colin. Upvote 0
I'm not sure I understand Erel. Do you mean the panel that shows the photo/preview? The layout is already on a panel (pnlDetails) & it's being set as you suggest in the designer script. Can you explain why I'm getting the casting error when I try to resize a view using SetLayout or when I try to rerun the designer script? Thanks - Colin.
Erel B4X founder Staff member Licensed User Longtime User Dec 11, 2013 #6 The point is to use AddTab instead of AddTab2. When you call AddTab2 the panel internal layout is set to a special layout that fills the Tab automatically. Upvote 0
The point is to use AddTab instead of AddTab2. When you call AddTab2 the panel internal layout is set to a special layout that fills the Tab automatically.
Computersmith64 Well-Known Member Licensed User Longtime User Dec 11, 2013 #7 OK - well I tried that & now I can't set my scrollview.panel.height to the correct height. It seems to be short by about the same amount of space that the tab at the top of the TabHost takes up. Also, my photo panel & buttons are still extending past the right edge of the screen. Upvote 0
OK - well I tried that & now I can't set my scrollview.panel.height to the correct height. It seems to be short by about the same amount of space that the tab at the top of the TabHost takes up. Also, my photo panel & buttons are still extending past the right edge of the screen.
Computersmith64 Well-Known Member Licensed User Longtime User Dec 11, 2013 #8 OK - after a LOT of screwing around, I managed to get it to work right. Here is what I arrived at after a whole bunch of trial & error: 1) Removed the panel from my details layout ("details") so that all the views have the Activity as the parent; 2) Created a ScrollView layout ("svlayout"), that ; 3) Loaded the TabHost layout ("TabHost") into the Activity; 4) Used .AddTab to load "svlayout" into the TabHost; 5) Used .Panel.LoadLayout to add the "details" layout into the ScrollView Once I did it this way, all the views lined up correctly without any layout changes having to be made in code. Here's the code: Code: Copy Sub Activity_Create(FirstTime As Boolean) Activity.LoadLayout("TabHost") tabDetails.AddTab("Pet Details", "svlayout") vScroll.Panel.LoadLayout("details") vScroll.Panel.Height = btnSaveAdd.Top + btnSaveAdd.Height + 5dip End Sub This seems to me to be a very convoluted way to go about things, but I'm just happy that it now works. - Colin. Upvote 0
OK - after a LOT of screwing around, I managed to get it to work right. Here is what I arrived at after a whole bunch of trial & error: 1) Removed the panel from my details layout ("details") so that all the views have the Activity as the parent; 2) Created a ScrollView layout ("svlayout"), that ; 3) Loaded the TabHost layout ("TabHost") into the Activity; 4) Used .AddTab to load "svlayout" into the TabHost; 5) Used .Panel.LoadLayout to add the "details" layout into the ScrollView Once I did it this way, all the views lined up correctly without any layout changes having to be made in code. Here's the code: Code: Copy Sub Activity_Create(FirstTime As Boolean) Activity.LoadLayout("TabHost") tabDetails.AddTab("Pet Details", "svlayout") vScroll.Panel.LoadLayout("details") vScroll.Panel.Height = btnSaveAdd.Top + btnSaveAdd.Height + 5dip End Sub This seems to me to be a very convoluted way to go about things, but I'm just happy that it now works. - Colin.