Android Question Help with Designer

Alisson

Active Member
Licensed User
Hi!!!

I can create an interface in Visual Designer, then extract the code for B4A ?

I created a simple interface in the Visual Designer , now want to extract the code automatically of the interface, positions of components.
Is possible?

Thank you very much
 

Attachments

  • VisualDesigner.png
    VisualDesigner.png
    53.7 KB · Views: 377
I am not shure, if I understand your question: if you want to get the position of the views, it is just something like this one:
Code: Copy
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Layout1")
  
    For Each v As View In Activity.GetAllViewsRecursive
        Dim ref As Reflector 'get the class; this is not necessary
        ref.Target = v  'this is not necessary
        Log(ref.RunMethod("getClass"))  'this is not necessary
        'get the position
        Log("Left " & v.left & " Top " & v.Top & " Width " & v.Width & " Height " & v.Height)
    Next

End Sub
 
Upvote 0
Why do you need it?

Just load the layout with Activity.LoadLayout.

@eurojam why do you add the "not required" code to your example? It only makes it more complicated.

Code: Copy
For Each v As View In Activity.GetAllViewsRecursive
   Log("Left " & v.left & " Top " & v.Top & " Width " & v.Width & " Height " & v.Height)
Next
 
Upvote 0
This is not the correct way to get the type.

The correct way is with:
Code: Copy
If v Is Label Then
 Dim lbl As Label = v
End If
This code will also handle all views that are subclasses of label (button, checkbox and others). In most cases it is good as you can treat many views with the same code.

If you want to get the exact type:
Code: Copy
Log(GetTYpe(v))

With that said, the visual designer is very powerful. Almost everything that can be done with code is simpler to implement with anchors and designer script.
 
Upvote 0
Erel, my project needs to http request.
The answer assembles the design of the interface.
A label may or may not exist in a http response .
Do you think this inappropriate my procedure?
 

Attachments

  • screen.png
    screen.png
    24.8 KB · Views: 357
Upvote 0
DonManfred , I read your post, but I have some questions that will help to develop , I think 90 % of my apps.
In my desinger I have the Labels , ImagesView , Panel among others.
In my code I have :

Code: Copy
Activity.LoadLayout("1")
Label1.Initialize("Label1") 
Label1.Text = "Hello world"

When I started the label and passed a value , my application stopped and did not change in my interface designer .
When you say leave the Label inivisível is like:
Code: Copy
panel.visible = true
?
Thank you for your help.
 
Upvote 0
you should NOT initialize views added in the designer!!!!!
 
Upvote 0
Back
Top