Android Question Droppy setYOffset not working

RB Smissaert

Well-Known Member
Licensed User
Integrated the Droppy library in my app now:
https://www.b4x.com/android/forum/threads/droppy-dropdown-menu.81918/
and all working very well. There is only one thing I can't get to work yet and that is
the setYOffset method. As I understand it this should move the top of the dropdown
vertically, related to the anchor view. It doesn't do anything though.
As some people might be interested to see how Droppy is used I post the full code.

B4X:
Sub Activity_CreateMenu(Menu As ACMenu)
 
 Dim i As Int
 Dim item As ACMenuItem
 Dim bmd As BitmapDrawable
 
 General.RunLog("Activity_CreateMenu")

 SetupIcons 'this needs a DB connection!

 Menu.Clear
 
 'initialize with default value (not in menu group)
 '-------------------------------------------------
 For i = 0 To 21
  arrMenuIconsInfo(i, 0) = -1
 Next
 
 bmd = TextToBitmapDrawable(Chr(61762),32,Colors.Black,48,48,Typeface.FONTAWESOME,"CENTER")
 'bmd = TextToBitmapDrawable(Chr(58836),32,Colors.Black,48,48,Typeface.MATERIALICONS,"CENTER") 'shows too small

 'Menu group 1
 For i = eMenuButtonType.FindPatient To eMenuButtonType.Map   '0 to 7
  item = Menu.AddWithGroup2(1, i, i, arrMenuIconFilesTitles(i, 2), arrMenuIcons(i, 0))
  item.ShowAsAction = item.SHOW_AS_ACTION_ALWAYS
  arrMenuIconsInfo(i, 0) = 1 'menu group 1
  arrMenuItems(i) = item 'menu item
 Next
 'easier to add overflow item to all menu groups
 item = Menu.AddWithGroup2(1, 8, 8, "Overflow", bmd)
 item.ShowAsAction = item.SHOW_AS_ACTION_ALWAYS
 
 'Menu group 2
 For i = eMenuButtonType.Appointments To eMenuButtonType.Phone_Patient   '8 to 14
  item = Menu.AddWithGroup2(2, i, i, arrMenuIconFilesTitles(i, 2), arrMenuIcons(i, 0))
  item.ShowAsAction = item.SHOW_AS_ACTION_ALWAYS
  arrMenuIconsInfo(i, 0) = 2
  arrMenuItems(i) = item
 Next
 item = Menu.AddWithGroup2(2, 15, 15, "Overflow", bmd)
 item.ShowAsAction = item.SHOW_AS_ACTION_ALWAYS
 
 'Menu group 3
 For i = eMenuButtonType.SQL To eMenuButtonType.Show_All_Run_SQL   '15 to 21
  item = Menu.AddWithGroup2(3, i, i, arrMenuIconFilesTitles(i, 2), arrMenuIcons(i, 0))
  item.ShowAsAction = item.SHOW_AS_ACTION_ALWAYS
  arrMenuIconsInfo(i, 0) = 3
  arrMenuItems(i) = item
 Next
 item = Menu.AddWithGroup2(3, 22, 22, "Overflow", bmd)
 item.ShowAsAction = item.SHOW_AS_ACTION_ALWAYS
 
 ActionBar.Menu.SetGroupVisible(2, False)
 ActionBar.Menu.SetGroupVisible(3, False)
 ActionBar.Menu.SetGroupVisible(1, True)
 iCurrentMenuGroup = 1
 
 AddDroppy
 

 ActionBar.InitMenuListener
 StartInterface
 
 
End Sub

Sub AddDroppy
 
 'Droppy is wrapper library from this:
 'https://github.com/shehabic/Droppy
 '------------------------------------
   
 Dim i As Int
 Dim arrLabels(23) As Label
 Dim arrSeparators(23) As Boolean

 btnDroppyAnchor.Initialize("btnDroppyAnchor")
 btnDroppyAnchor.Color =  Colors.RGB(255, 255, 32) 'color of actionbar
 btnDroppyAnchor.Visible = True 'needs to be visible to anchor to the button
 ActionBar.AddView(btnDroppyAnchor,1,1,Gravity.RIGHT) '0,0 won't work as causes intermitten faint outline on actionbar
 
 pop.Initialize("Droppy", btnDroppyAnchor)
 
 arrSeparators(3) = True
 arrSeparators(8) = True
 arrSeparators(14) = True
 
 For i = 0 To 22 '21 to 45
  arrLabels(i).Initialize("lbl")
  arrLabels(i).Tag = i 'not sure we will need this
  arrLabels(i).Color =  Colors.White
  arrLabels(i).Height = 28dip
  arrLabels(i).Width = 240dip
  arrLabels(i).Gravity = Gravity.CENTER_VERTICAL
  arrLabels(i).Padding = Array As Int(8dip,0,0,0)
  arrLabels(i).TextSize = 16
  arrLabels(i).TextColor = Colors.Black
  arrLabels(i).Text = arrMenuIconFilesTitles(i + 22, 2) 'as 22 non-overflow menu items
  
  pop.addMenuItem3(arrLabels(i)).addclickcallback.addonDismissCallback
  If arrSeparators(i) Then
   pop.addSeparator
  End If
 Next
 
 'setYOffset doesn't do anything '<<<<<<<<<<<
 pop.triggerOnAnchorClick(False).setYOffset(10).build
 
End Sub


'Sub Droppy_onClicked(view As Object, index As Int)
' Log($"Droppy_onClicked(${view}, ${index})"$)
'End Sub

'although this only does a log the Sub is needed as otherwise there will be an error, missing 'on_Dismissed
Sub Droppy_onDismissed()
 Log($"Droppy_onDismissed()"$)
End Sub

Sub ShowOverflow
 
 If bKeyboardVisible Then
  HideKeyboard
  Sleep(140) 'this is needed
 End If
 
 pop.show
 
End Sub

Sub HideKeyboard()

 ime.HideKeyboard
 bKeyboardVisible = False
 
End Sub

Sub lbl_Click
 
 Dim lbl As Label = Sender
 
 General.RunLog("lbl_Click, lbl.Text: " & lbl.Text)
 
 Select Case lbl.Text
  Case "Settings"
   GotoPanel(ePanelType.Settings, False, True)
  Case "Export to .csv"
   CurrentResultSet2CSV(Null)
  Case "Import .csv"
   ImportCSV
  Case "Show .xls"
   ShowXLS
  Case "Show .txt or .csv"
   ShowCSV_TXT
  'ETC.     
 End Select
 
 pop.dismiss(True)
 
End Sub
Any advice how setYOffset should be used?


RBS
 

RB Smissaert

Well-Known Member
Licensed User
Solved this now by adding btnDroppyAnchor to a panel, added to the actionbar.
That way there is more control over the left and top of the Droppy menu.

RBS
 
Top