Gravity Question

manios

Active Member
Licensed User
Longtime User
Hi,

is it possible to set 2 or more Gravity items?

Example: I want 2 Garvity settings on a label!

label1.Gravity = Gravity.RIGHT
label1.Gravity = Gravity.CENTER_VERTICAL

It seems only the last Gravity setting is used.
 

kickaha

Well-Known Member
Licensed User
Longtime User
As they show as Ints (I assume they are bits really), you can add them to combine:
B4X:
label1.Gravity = Gravity.RIGHT + Gravity.CENTER_VERTICAL
 
Upvote 0

manios

Active Member
Licensed User
Longtime User
Thanks Eril for clearifying this!
 
Upvote 0

Djembefola

Active Member
Licensed User
Longtime User
What am i doing wrong?

Hi,
I have a Variable g, which contains two combined Gravity Constants and want to find out, if the bits for gravity.CENTER_HORIZONTAL are set.

The Value of the Variable g was assigned with:
B4X:
g = Bit.OR(gravity.TOP, gravity.CENTER_HORIZONTAL)

My idea was to test the Variable g for CENTER_HORIZONTAL with the following code:

B4X:
If Bit.AND(g, gravity.CENTER_HORIZONTAL) = gravity.CENTER_HORIZONTAL then
   ...(do something)
End If

this seems to be a bad idea, my code doesn't work:


B4X:
Log (Gravity.CENTER_HORIZONTAL)                ->   1
Log (Gravity.LEFT)                             ->   3
Log (Gravity.RIGHT)                            ->   5
Log (Gravity.TOP)                              ->  48
            
g=Bit.Or(Gravity.TOP,Gravity.CENTER_HORIZONTAL)->  49                        

Log (g)                                        ->  49                                
Log (Bit.AND(g,Gravity.TOP))                   ->  48
Log (Bit.AND(g,Gravity.CENTER_HORIZONTAL))     ->   1
Log (Bit.AND(g,Gravity.LEFT))                  ->   1   
Log (Bit.AND(g,Gravity.RIGHT))                 ->   1

With Bit.And i get the same result (1) for LEFT, RIGHT And CENTER_HORIZONTAL

What am i doing wrong? How can i check variables for gravity.CENTER_HORIZONTAL?

Regards,


Joerg
 
Upvote 0

Djembefola

Active Member
Licensed User
Longtime User
Thank you for your quick reply.

Dealing with the first four bits is too much mathematics for a Basic-Programmer :)
As a Workaround i will test for LEFT and RIGHT instead.

Regards,
Joerg
 
Upvote 0
Top