Android Question TabStrip relative positioning

Robert Valentino

Well-Known Member
Licensed User
Longtime User
I have this code that gets me the relative position of a field on the screen
B4X:
Private Sub GetRelative_LT(RelativeLT As TRelativeLT, V As JavaObject) As TRelativeLT
           
           Try
               '-----------------------------------------------------------------------------------------------------------------
               '  Just in case the Passed Structure has not been Initialized
               '-----------------------------------------------------------------------------------------------------------------
               If  RelativeLT.IsInitialized = False Then
                   RelativeLT.Initialize
               End If
               
               '-----------------------------------------------------------------------------------------------------------------
               '  Get the Parent to this View
               '-----------------------------------------------------------------------------------------------------------------
                 Dim parent      As Object = V.RunMethod("getParent", Null)
               
               '-----------------------------------------------------------------------------------------------------------------
               '  If Parent is Null then Done
               '-----------------------------------------------------------------------------------------------------------------
                 If  parent = Null                                                                            Then
                   Return RelativeLT
               End If

               '-----------------------------------------------------------------------------------------------------------------
               '  If Parent Type is ANY of these we are Done
               '-----------------------------------------------------------------------------------------------------------------
                 Dim parentType As String = GetType(parent)

               Log("parentType:" &parentType)     
               

               '-----------------------------------------------------------------------------------------------------------------
               '  It turns out that if we get the Parent of the ScrollView we can work our way right down the children               
               '-----------------------------------------------------------------------------------------------------------------
               If  parentType = "anywheresoftware.b4a.objects.ScrollViewWrapper$MyScrollView"               Then
                   V        = parent
                   parent    = V.RunMethod("getParent", Null)
                   
                   If  parent = Null Then
                       Return RelativeLT
                   End If
               End If
               
                 If  parentType = "android.widget.FrameLayout"                                               Then Return RelativeLT
               If  parentType = "anywheresoftware.b4a.objects.HorizontalScrollViewWrapper$MyHScrollView"   Then Return RelativeLT
               If  parentType = "flm.b4a.scrollview2d.ScrollView2DWrapper$MyScrollView"                   Then Return RelativeLT       
                 If  parentType = "android.widget.FrameLayout$LayoutParams"                                   Then Return RelativeLT       
                 If  parentType = "anywheresoftware.b4a.objects.IME$ExtendedBALayout"                       Then Return RelativeLT
                 If  parentType = "anywheresoftware.b4a.BALayout$LayoutParams"                               Then Return RelativeLT

'               Log("parentType2:" &parentType)     

               '-----------------------------------------------------------------------------------------------------------------
               '  OK - ADD on this Views Left and Top variables
               '-----------------------------------------------------------------------------------------------------------------
                   Dim VW As View = V

               RelativeLT.Left = RelativeLT.Left + VW.Left
               RelativeLT.Top  = RelativeLT.Top  + VW.Top
               
               '-----------------------------------------------------------------------------------------------------------------
               '  Get the settings for our Parent
               '-----------------------------------------------------------------------------------------------------------------               
               Return GetRelative_LT(RelativeLT, parent)               
           Catch
               '-----------------------------------------------------------------------------------------------------------------
               '  I DO NOT like just catching errors
               '    But if we are here then I have missed some new type Log a then Exception msg and Consider this as DONE
               '-----------------------------------------------------------------------------------------------------------------
               Log(LastException.Message)
               
               Return RelativeLT
           End Try               
End Sub

I just added a TabStrip to my program and now I am hitting a new ParentType
I am assuming the TabStrip is producing this new layout type
B4X:
   If  parentType = "androidx.viewpager.widget.ViewPager$LayoutParams" Then
      Return RelativeLT
   End If
[/code}

and do not know how to process this type.  How do I get the Left / Top for a TabStrip

BobVal
 

Robert Valentino

Well-Known Member
Licensed User
Longtime User
I have a dropdown class that positions the dropdown list relative to the a panel on the screen (tries down and right, down and left, up and left, up and right, and center left or center right - looking for best fit)

Because I cannot calculate where I am on the screen (relative to the 0, 0) it is list box is being positioned in the wrong place (see attached image).

Getting the relative (I guess it really is absolute - relative to screen location 0, 0) position of the display box allows me to see how much space I have around it in order to display my list box for the user to pick from

This is my first app using TabStrip (I have been using AHViewPager, AHViewPagerFixedTabs, AHPageContainer) - maybe I should change the app to use them at least I can get the location of everything on the screen?

Tried putting TabStrip in panel but not sure how that helps me?

BobVal
 

Attachments

  • Screenshot_2019-09-27-17-47-46.png
    Screenshot_2019-09-27-17-47-46.png
    45.1 KB · Views: 225
Upvote 0

Robert Valentino

Well-Known Member
Licensed User
Longtime User
Found that this worked

B4X:
Public  Sub GetTabStripHeight(tabstrip As TabStrip) As Float
               Dim jo    As JavaObject = tabstrip
               Dim r    As Reflector
           
               r.Target = jo.GetField("tabStrip")
           
               Dim tc    As Panel  = r.GetField("tabsContainer")
           Dim o   As Object = tc.Parent
           
           If o <> Null Then
               Dim p As Panel = o
               
               Return p.Height
           End If
           
               Return 0
End Sub
 
Upvote 0
Top