Android Question TabStripViewPagerExtendet - SetTabPadding

rgarnett1955

Active Member
Licensed User
Longtime User
Hi,

I have tried this class, but I get strange behavior. If I run the debugger and put a breakpoint at line 30:

Set Padding Method:
'My code ...
For Each row() As Object In tabPageList
        If k = 1  Then
            addVegGrp = True
            tblVegGrpArg.ID = row(0)
            tblVegGrpArg.GroupName = row(1)
        Else
            addVegGrp = False
        End If
            
        TabStrip1.LoadLayout("Page1", row(1))
        tbs.SetTabPadding(TabStrip1, Array As Int(0dip, 0dip, 0dip, 0dip)  , k - 1)

        Activity.AddMenuItem(row(0), "mnu" & k)
        k = k + 1
        
    Next


'-----------------------------------------------------------------------------------
'Class Method

'Set the Padding of a Tab
Public Sub SetTabPadding(tabstrip As TabStrip, padding() As Int,Position As Int)
    
    Dim i As Int
    For Each lbl As Label In GetAllTabLabels(tabstrip)
        If i = Position Then
            
            lbl.Padding = padding  <--- Breakpoint here

        End If
        i = i + 1
    Next
    
End Sub


When I step over the lbl.Padding = padding statement the Tab padding changes on the screen, but when I return from the method back to my code the tab changes back to the default.

Does anyone know what is happening and how I might fix it?

The standard right and left padding for the tab appears to be ~48dip which is a lot of white space. I would like to reduce it to about 24 to fit more tabs on the screen.

Best regards
Rob
 

rgarnett1955

Active Member
Licensed User
Longtime User
Hi,

I fixed the problem with the following code - I added a new method to the class that sets all tabs the same in one go:

B4X:
'My code that uses the new method'
'======================================================================================================
private Sub setTabPages(tblVegGrpArg As tblVegGrp_t)
    Dim tabPageList As List = Starter.dbGB.getVegGroupRecords
    Dim k As Int = 1
    Dim props As Map
    
    Dim tbs As  TabStripExt   
    tbs.Initialize

    props.Initialize

    'Common properties of tab
    props.Put("HorizontalAnchor", "Both")
    
    For Each row() As Object In tabPageList
        If k = 1  Then
            addVegGrp = True
            tblVegGrpArg.ID = row(0)
            tblVegGrpArg.GroupName = row(1)
        Else
            addVegGrp = False
        End If
            
        TabStrip1.LoadLayout("Page1", row(1))

        Activity.AddMenuItem(row(0), "mnu" & k)
        k = k + 1
        
    Next

    tbs.SetTabsAllPadding(TabStrip1, Array As Int(12dip, 0dip, 12dip, 0dip))

    TabStrip1.ScrollTo(0, True)
    currentTabSelected = 0
    
    'Set the exercise list view_Col
'    setcvLogList(currentTabSelected)
End Sub


'Additional methods


'Set the Padding of all Tabs *****  added by rgarnett1955 ****

'Example call
'tbs.SetTabsAllPadding(TabStrip1, Array As Int(20dip, 0dip, 20dip, 0dip))

Public Sub SetTabsAllPadding(tabstrip As TabStrip, padding() As Int)

    For Each lbl As Label In GetAllTabLabels(tabstrip)
            lbl.Padding = padding
    Next
    
End Sub
'

This works fine.

Probably need to do this with all of the methods, but I don't have time now to test this.

I renamed the class to shorten the name a bit and have attached it to this post.

Best regards

Rob
 

Attachments

  • TabStripExt.bas
    8.4 KB · Views: 273
Upvote 0
Top