Android Question TabStripViewPager - How to speed up layout loading

ernschd

Active Member
Licensed User
Longtime User
Hello,

in my app I use the AHViewPager library in combination with AHViewPagerTabs to display content in Tabs. The displaying of 23 entries takes about 0.8 seconds.
I am in the process of modernizing the app and wanted to switch to TabStripViewPager. Unfortunately loading and displaying the 23 entries here takes between 1.6 and 2.4 seconds, so 2-3 times as long.
This is not reasonable for my users.

Is there a way to speed up the process? A sample project is attached.

Thanks in advance.
 

Attachments

  • TabSpeedTest.zip
    12.2 KB · Views: 111

Erel

B4X founder
Staff member
Licensed User
Longtime User
I made the following tests, in release mode of course:

1: with TabStrip
B4X:
Sub Button1_Click
    Dim n As Long = DateTime.Now
    For i = 0 To 23
        tabs.LoadLayout("gerdat_content", i)
    Next
    Log(DateTime.Now - n)
End Sub

2: without tabstrip
B4X:
Sub Button1_Click
    Dim n As Long = DateTime.Now
    For i = 0 To 23
        Dim p As B4XView = xui.CreatePanel("")
        p.SetLayoutAnimated(0, 0, 0, 200dip, 200dip)
        p.LoadLayout("gerdat_content")
    Next
    Log(DateTime.Now - n)
End Sub

3: with TabStrip, loading an empty layout.

The results on my device are:
1: 350ms
2: 250ms
3: 55ms

My conclusion is that TabStrip is not the problem. Loading your complex layout 23 times is the slow part (which is not too slow on my device).

The solution is simple. Don't create 23 full tabs immediately. Load the first one and load the others when needed. You can start with empty tabs and later load.
 
Upvote 0

ernschd

Active Member
Licensed User
Longtime User
I have another question on this topic: I create the tabs with an empty layout. Then I load the correct (complex) layout in the first tab.
If another tab is called, I would like to use a copy of the layout of the first tab for the current one (because loading of this layout takes quite a long time).
For this purpose, I load the layout once into another panel and created an array of panels with the same dimension as the number of tabs, for example
B4X:
DIM PanelArray(23) AS Panel

When calling a tab I wanted to load the panel with the layout using
B4X:
PanelArray(X).AddView(PanelWithComplexLayout, 0, 0, 100%x, 100%y)
Unfortunately I get the message "The specified child already has a parent. You must call removeView() on the child's parent first" . Unfortunately this does not work.

How do I do it correctly?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Loading of a single layout doesn't take quite a long time. You are optimizing things that don't need to be optimized. Measure it (in release mode).

B4X:
Dim Panels As List

Dim pnl As B4XView = Panels.Get(X)
If PanelWithComplexLayoutWhichShouldAlsoBeB4XView.Parent.IsInitialized Then PanelWithComplexLayoutWhichShouldAlsoBeB4XView.RemoveViewFromParent
pnl.AddView(PanelWithComplexLayoutWhichShouldAlsoBeB4XView, 0, 0, pnl.Width, pnl.Height)
 
Upvote 0

ernschd

Active Member
Licensed User
Longtime User
Sorry, I do not understand the example.
When (and with what) will the Panels list be filled?
And how can I create a layout as B4XView? Are there links to read about this topic?
 
Upvote 0

ernschd

Active Member
Licensed User
Longtime User
Ok, I've got it now. The speed is definitely better then my Version.
I hope I have understood the concept.
 

Attachments

  • TabSpeedTest.zip
    13.4 KB · Views: 101
Upvote 0

ernschd

Active Member
Licensed User
Longtime User
Unfortunately, there is still a small problem with this solution: when swiping through the individual tabs, the next tab is only displayed when it is completely loaded.
screenshot.png
Usually you can see the content already before that. I'm not sure if my users like this so much.
Does anyone have an idea?
 
Upvote 0

ernschd

Active Member
Licensed User
Longtime User
I switched to TabLayout from corwin42s DesignSupport-Library. It is fast enough to load all tabs in advance.
It also makes it easier to port the existing code. I thank you anyway for your efforts!
 
Upvote 0
Top