Android Question How to Drag to resize panels?

tsteward

Well-Known Member
Licensed User
Longtime User
I want two panels. Top panel and Bottom panel to start at top panel 25% of screen height and bottom panel 75%of screen height.
I want to be able to drag a divider or something between them to make them resize.
Ie drag the divider down to make the top panel larger and the bottom panel smaller etc.

Is there a library or class that already does this?
Is it possible?
 

mangojack

Expert
Licensed User
Longtime User
needs a bit of refinement ..

B4X:
Sub Activity_Create (FirstTime As Boolean)

   Panel1.Initialize("")
   Panel2.Initialize("")
   Panel3.Initialize("panel3") ' panel3 is the divider ... can be thinned down if needed
   Panel1.Color = Colors.Blue
   Panel2.Color = Colors.Red
   Panel3.Color = Colors.White
   Activity.AddView(Panel1,0, 0, 100%X, 25%Y)
   Activity.AddView(Panel2,0, 25%X, 100%X, 75%Y)
   Activity.AddView(Panel3,0, 25%X, 100%X, 10dip)

   yPos = 120  ' 25% 320x480 height

End Sub

Sub panel3_Touch (Action As Int, X As Float, Y As Float)

   If Action = 2 Then
     Panel3.Top = Y + yPos
     Panel1.SetLayout(0, 0, 100%X, Panel3.Top)
     Panel2.SetLayout(0, Panel3.Top, 100%x,100%Y - Panel3.Height)
     yPos = Panel3.Top
  End If

End Sub

You might be interested in this also.. the first post by Erel demonstrating a dragable view ..
Classes are Coming ...
 
Last edited:
Upvote 0

klaus

Expert
Licensed User
Longtime User
Here is another one with only two Panels.
Attached the small test program.
B4X:
Sub Globals
    Dim PanelY0, PanelHeight, PanelMargin As Int
    Dim PanelMove = False As Boolean
    Dim pnlTop, pnlBottom As Panel
End Sub

Sub Activity_Create(FirstTime As Boolean)
    PanelMargin = 10dip
    PanelY0 = 25%y
    pnlTop.Initialize("")
    pnlTop.Color = Colors.Blue
    Activity.AddView(pnlTop, PanelMargin, PanelMargin, 100%x - 2 * PanelMargin, PanelY0 - 1.5 * PanelMargin)
    pnlBottom.Initialize("")
    pnlBottom.Color = Colors.Blue
    Activity.AddView(pnlBottom, PanelMargin, PanelY0 + PanelMargin / 2, 100%x - 2 * PanelMargin, 100%y - PanelY0 - 1.5 * PanelMargin)
End Sub

Sub Activity_Touch (Action As Int, X As Float, Y As Float)
    Select Action
    Case Activity.ACTION_DOWN
'        If Y >= pnlTop.Top + pnlTop.Height AND Y <= pnlBottom.Top Then
        If Y >= pnlTop.Top + pnlTop.Height - PanelMargin AND Y <= pnlBottom.Top + PanelMargin Then ' widens the touch area
            PanelY0 = Y
            PanelHeight = pnlTop.Height
            PanelMove = True
        End If
    Case Activity.ACTION_MOVE
        Dim H = PanelHeight + Y - PanelY0 As Int
        If PanelMove = True AND H >=25%y - 1.5 * PanelMargin AND H <= 75%y - 1.5 * PanelMargin Then
            pnlTop.Height = H
            pnlBottom.Top = pnlTop.Top + pnlTop.Height + PanelMargin
            pnlBottom.Height = 100%y - pnlBottom.Top - PanelMargin
        End If
    Case Activity.ACTION_UP
        PanelMove = False
        PanelY0 = pnlBottom.Top - PanelMargin / 2
    End Select
End Sub
 

Attachments

  • TwoPanels.zip
    6.1 KB · Views: 202
Upvote 0
Top