Android Question How to resize panels ?

Ondra

Member
Licensed User
Longtime User
Hi, I am new at B4A. So can you please help me with my problem ? I would like to make program with floating panels, whitch could be resized like in designer. So I used draggable view for moving panels and it is works fine. Then I tried to define 8 small button in panel and set him fixed possitions on the edge of panel. (Like the red squares in abstract designer). But if I run the program, 8 panels are bring together in one corner and still have no idea, how to make that panel resizable. There is "my" code for the class module:

B4X:
'Class module
Sub Class_Globals
    Private innerView As View
    Private panel1 As Panel   
    Private downx, downy As Int
    Private ACTION_DOWN, ACTION_MOVE, ACTION_UP As Int
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(Activity As Activity, v As View)
innerView = v
panel1.Initialize("")
panel1.Color = Colors.Transparent
Activity.AddView(panel1, v.Left, v.Top, v.Width, v.Height)
ACTION_DOWN = Activity.ACTION_DOWN
ACTION_MOVE = Activity.ACTION_MOVE
ACTION_UP = Activity.ACTION_UP
Dim r As Reflector
r.Target = panel1
r.SetOnTouchListener("panel1_Touch")

End Sub

Private Sub Panel1_Touch( o As Object, ACTION As Int, x As Float, y As Float, motion As Object) As Boolean
If ACTION = ACTION_DOWN Then
    downx = x
    downy = y
Else
    innerView.Left = innerView.Left + x - downx
    innerView.Top = innerView.Top + y - downy
    panel1.Top = innerView.Top
    panel1.Left = innerView.Left
End If

Return True
End Sub

And the main one:

B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim Button1 As Button   
    Dim Button2 As Button
    Dim EditText1 As EditText
    Dim panel2 As Panel
   
    Private btnpanel1 As Button
    Private btnpanel2 As Button
    Private btnpanel3 As Button
    Private btnpanel4 As Button
    Private btnpanel5 As Button
    Private btnpanel6 As Button
    End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("1")
    Dim dv1, dv2, dv3, dv4, dv5 As DraggableView
    dv1.Initialize(Activity, Button1)
    dv2.Initialize(Activity, Button2)
    dv3.Initialize(Activity, EditText1)
    dv4.Initialize(Activity, panel2)
    dv5.initialize(panel2, btnpanel1)
    End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Could somebody please help me ?
Thank you. And sorry for my bad english :)
 

NJDude

Expert
Licensed User
Longtime User
The problem is that you are using variants, it is better to use the designer scripts, take a look at the attached project, it's your code with some modifications.
 

Attachments

  • Panely_modified.zip
    8.3 KB · Views: 252
Upvote 0

Ondra

Member
Licensed User
Longtime User
Thanks for help ! That solves my problem with bringing together. Now I would like to make function, that allows to user resize that panel like in abstract designer. So by click on one of red squares and resize it by flick of a finger :)
 
Upvote 0

Ondra

Member
Licensed User
Longtime User
Thank you. This code is a little bit complicated. I hope, that I would be able to understand :-D
 
Upvote 0
Top