Android Question Newby question about center on different screens

MarianoD

Member
Licensed User
Longtime User
Hello, please apologize my english, i dont have too much experience in B4A, my question is:

I have an Activity, with a Layout, the Layout has an image (for a logo) some labels and edittexts to enter information, and a button at bottom. Wich is the EASY way to center the labels on screen to see it property no metter if 3.5" old phone or a 6" new one, can i do something like:

button.left = ((screen.width - button.width)/2) ?

I disabled screen rotation, and set it to PORTRAIT, so i dont need to worry about screen rotation (app will be used mostly in cell phones, not tablets)

Thanks in advance!
Mariano.
 

MarianoD

Member
Licensed User
Longtime User

Thanks Bill, if i dont understand wrong... if i put an image, and use horizontalanchor=both and verticalanchor=top then that image willl be always centered and in top of any screen? Is correct? And the same, just using verticalanchor=bottom, to set a button centered in bottom? No metter where that button or image are positioned on design, in the layout?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
in top of any screen?
in top of the activity you are running resp. loading the layout, yes. Not automatically in all activities.
And the same, just using verticalanchor=bottom, to set a button centered in bottom?
It is anchored to the botton. It has nothing to do with centered. If you do not place in the center then it will not be centered. But it is anchored to the bottom. Say you have put it to 10dip from bottom. It will be always at the bottom with a 10dip space.

Watch the tutorial again. As often until you understand it.

For ANY new question: please create a NEW thread.
 
Upvote 0

BillMeyer

Well-Known Member
Licensed User
Longtime User
@MarianoD

I would add to what @DonManfred has said above the following:

Try using (In your Designer) Tools--> Send to UI Cloud (or press F6) and wait a few seconds and then you can see the effect of your design on different common devices.

This way you will quickly see how the different layouts perform. This is of course secondary to having a real device connected to your system.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
To center horizontally you could use, in the DesignerScripts, button.HorizontalCenter = 50%x instead of button.left = ((screen.width - button.width)/2).
I would suggest you to use a Panel, put all your views onto this Panel and then center this panel with Panel.HorizontalCenter = 50%x and Panel.VerticalCenter = 50%y.
You may also use AutoScaleAll to slightly increase the view dimensions.
If the Panel height is bigger than the screen height you could use a ScrollView and load the Panal onto the internal panel of the ScrollView.
You might also have a look at the B4X Visual Designer Booklet.
 
Upvote 0

MarianoD

Member
Licensed User
Longtime User
Ok, thats enough for me! Time to work! Thanks Bill and Claud. And Don, yes, i will see tutorial as often as i understand it, sometimes is easy for me write on english, because i use common words, but not to easy to read and understand long texts. Thanks all.
 
Upvote 0
Top