Android Example Create your layouts based on percentages

[EDIT: my Adapt your layouts using SetLayout is more useful]

Waiting for this feature in the Designer
(I don't know if Erel will add it, see these threads:
https://www.b4x.com/android/forum/threads/anchors.56119/
https://www.b4x.com/android/forum/threads/designer-code-generator.55843/
)

you could use my module modPercLayoutGen (it is in the project attached).

As you can see in the project, you should:

a) initialize the module (Main Activity)
b) call modPercLayoutGen.GeneratePercLayoutCode, passing the Activity and the Activity name to it.


You should use two measures:

1) set the tag of each view to the name of the view;
2) call modPercLayoutGen.Close after the last call to the generation routine;



Sample Output:
B4X:
@@@@@@@@@@@@@@@@@@@@@     Main     @@@@@@@@@@@@@@@@@@@@@

#Region  * VIEWS DECLARATION

    ' Main content.
    Dim Button1 As Button
    Dim Button2 As Button
    Dim EditText1 As EditText
    Dim ImageView1 As ImageView
    Dim Panel1 As Panel

    ' Panel1 content.
    Dim Button3 As Button
    Dim Panel2 As Panel

    ' Panel2 content.
    Dim EditText2 As EditText
    Dim Button4 As Button
#End Region

#Region * VIEWS ADDITION

    ' Main
    Main.AddView(Button1, 0%x, 0%y, 9.141%x, 10.879%y)
    Main.AddView(Button2, 0%x, 15.35%y, 18.359%x, 10.879%y)
    Main.AddView(EditText1, 18.359%x, 15.35%y, 18.281%x, 10.879%y)
    Main.AddView(ImageView1, 4.609%x, 28.465%y, 27.422%x, 33.532%y)
    Main.AddView(Panel1, 0%x, 65.574%y, 36.641%x, 28.316%y)

    ' Panel1
    Panel1.AddView(Button3, 3.198%x, 7.895%y, 34.328%x, 84.737%y)
    Panel1.AddView(Panel2, 46.908%x, 7.895%y, 46.908%x, 84.737%y)

    ' Panel2
    Panel2.AddView(EditText2, 13.182%x, 0%y, 73.636%x, 54.658%y)
    Panel2.AddView(Button4, 13.182%x, 63.975%y, 73.636%x, 36.025%y)
#End Region
______________     End of Main     _____________________


@@@@@@@@@@@@@@@@@@@@@     actTwo     @@@@@@@@@@@@@@@@@@@@@

#Region  * VIEWS DECLARATION

    ' actTwo content.
    Dim Panel1 As Panel

    ' Panel1 content.
    Dim Button1 As Button
#End Region

#Region * VIEWS ADDITION

    ' actTwo
    actTwo.AddView(Panel1, 17.578%x, 11.968%y, 23.359%x, 39.761%y)

    ' Panel1
    Panel1.AddView(Button1, 5.017%x, 5.017%y, 50.167%x, 50.167%y)
#End Region

______________     End of actTwo     _____________________
 

Attachments

  • lm PercLayout.zip
    16.6 KB · Views: 529
Last edited:
Top