Android Question Animation based on screen size

Shay

Well-Known Member
Licensed User
Longtime User
Hi

I have simple animation - figure is starting on specific plan on screen and then move right/up..
with a1.InitializeTranslate("Animation", 0, 0, 80dip, 20dip)
the problem is on phone vs. tablet, the start location is different (due to screen resolution)
and also the movement is wrong
I assume I need to "math" it?
how do I do it?
1. Know start location + end location (left / top of images) based on device
2. Know the animation relative movements based on device

Thanks
 

ronell

Well-Known Member
Licensed User
Longtime User
use %x %y instread of dip to determine the location

for example

B4X:
'force the view in center of the screen
view.left = 50%x - view.width/2
view.top = 50%y - view.height/2


'you can also determine if the device is tablet or phone
 If GetDevicePhysicalSize > 6 Then
      '7'' or 10'' tablet
   Else
      'phone
   End If

Sub GetDevicePhysicalSize As Float
   Dim lv As LayoutValues
   lv = GetDeviceLayoutValues
   Return Sqrt(Power(lv.Height / lv.Scale / 160, 2) + Power(lv.Width / lv.Scale / 160, 2))
End Sub
https://www.b4x.com/android/forum/threads/device-type.17210/#post98356
 
Last edited:
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Sub GetDevicePhysicalSize As Float
Dim lv As LayoutValues
lv = GetDeviceLayoutValues
Return Sqrt(Power(lv.Height / lv.Scale / 160, 2) + Power(lv.Width / lv.Scale / 160, 2))
End Sub
Why reinvent the wheel? The below line gives you the screen size without waking up Pythagoras
B4X:
Log(lv.ApproximateScreenSize) 'gives you the screen size
 
Upvote 0

Shay

Well-Known Member
Licensed User
Longtime User
but the screen ratio are not the same between 1280 * 800 vs 420 * 320
 
Upvote 0

Shay

Well-Known Member
Licensed User
Longtime User

ok, I got some number 4.589389937671455 on phone, and 9.433981132056605 on tablet, what is the next step here?
 
Upvote 0

Shay

Well-Known Member
Licensed User
Longtime User
is there a way to load different variant on layout? (based on screen size?)
since I also tried:
ImageView2.Left = 100%x - 95%x
ImageView2.Top = 100%y - 50%y
and it still don't look good between tablet and phone
 
Upvote 0

Shay

Well-Known Member
Licensed User
Longtime User
I am trying to build this game:
My issue is that I have this as full background picture, and I need to move the girl from box 1 to box 23
and on different devices the location of the boxes are not the same, also the movement is not the same (left/top / dip)


 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…