Android Question Edittext gravity

Roger Daley

Well-Known Member
Licensed User
Longtime User
Hi All

A small problem with Edittext alignment.
I want the text to be Vertical_Center and Horizontal_Right. Using the designer I always end up with Vertical _Top no matter what the setting.???
In code when I use Gravity.Vertical_Center it is also Horizontal_Left.

I can't figure out how to use two gravity parameters in code. Is this possible?
[The padding is set to zero.]

Regards Roger
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
I've tried it with the designer and it works properly.

I can't figure out how to use two gravity parameters in code. Is this possible?
Yes.
Best option is to use B4XView when you can:
B4X:
Sub Globals
   Private EditText1 As B4XView
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("1")
   EditText1.SetTextAlignment("CENTER", "RIGHT")
End Sub

Or:
B4X:
EditText1.Gravity = Bit.Or(Gravity.CENTER_VERTICAL, Gravity.RIGHT)
 
Upvote 0

Roger Daley

Well-Known Member
Licensed User
Longtime User
I've tried it with the designer and it works properly.


Yes.
Best option is to use B4XView when you can:
B4X:
Sub Globals
   Private EditText1 As B4XView
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("1")
   EditText1.SetTextAlignment("CENTER", "RIGHT")
End Sub

Or:
B4X:
EditText1.Gravity = Bit.Or(Gravity.CENTER_VERTICAL, Gravity.RIGHT)


Thanks Erel. The Bit.Or is exactly what I need.

Regards Roger
 
Upvote 0
Top