Android Question orientations changes

a n g l o

Active Member
Licensed User
Longtime User
hello,
i use
B4X:
#SupportedOrientations: unspecified
i understand that the above is applied for an activity.
however, is there a way to let the activity change the orientation BUT prevent a view (panel in that activity) to make the change (should stay as is.) ?
thank you
 

Brian Dean

Well-Known Member
Licensed User
Longtime User
I cannot picture how that would work. Do you mean that you want some views to rotate with the device, but other views to remain fixed? If you really want to do that then I think that you will have to take control of the rendering - ie use a canvas - on the views that you do not want to rotate. But even then you would have to know whether the device had been rotated to the left or the right to know how to redraw the "fixed" view? And presumably you would have to prevent the other views overlapping your "fixed" view. Or have I got the wrong idea?

[Edit - or rather than use a canvas take a view.snapshot and rotate the image (if you knew which way to turn!)]
 
Last edited:
Upvote 0

a n g l o

Active Member
Licensed User
Longtime User
you are correct. if there's no way to prevent a panel to rotate with the activity - i'll have to take control and write code that will change the panel so it'll "LOOK" as if not changed. i know how to do that. np. but it's a lot of code to write and a lots of calculations, so i'll wait a while for a 1 line solution (if exists)....
you raise another issue that bothers me :

a follow-up question :
------------------------
i saw on the web pieces of java code that (i think) can tell if the device has rotated to landscape left or right and portrait up or down. can someone "translate" it to b4a ?

thank you
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
You should have started a new thread with your new question, but there is already quite a lot in the forum about rotation sensing . Telling which way the device has been rotated should be quite straightforward using the Phone library and the orientation sensor, but I have no experience of this.

Some other things that I have thought of, although you may have already thought of them too ...

- If you use Layouts then you might be able to avoid a lot of calculations. You could detect the screen orientation in Activity_Create() and load the appropriate layout ..

B4X:
    isLandscape = (100%x > 100%y)

- If you cast your panel to a B4XView then you can use the view.rotate method. I have not tried this so I do not know what happens to child views.

- There are other #supportedOrientations options available, such as "sensorPortrait" - see elsewhere in the forum.
 
Upvote 0

a n g l o

Active Member
Licensed User
Longtime User
ok, thanks.
i've got the desired result in code.
for detection of rotation type (left or right) i've found here some options and selected Erel's 1️⃣
Thank You
 
Upvote 0
Top