Android Question NineOldAndroids or Designer?

LucaMs

Expert
Licensed User
Longtime User
The project attached contains two panels, one added by Designer, the other by code.

Adding an animation (NineOldAndroids) the results are different (partially solved adding a x translation, in another project).

Is it due to the library or are there some differences between the two ways used to create the panels?


(do not worry about the back of the card; already solved in a Custom View ;))


Thank you.
 

Attachments

  • FlipPanel.zip
    24.7 KB · Views: 507

LucaMs

Expert
Licensed User
Longtime User
Are you talking about the layout animation (while the layout is loaded)?
No. You can see that the panels "rotate" on different pins (axis?); the panel on the top-left, added by code, rotates on its middle, the other on its right egde and this one moves to the left before turning. The code for the animation is the same for both panels.

Thank you, Erel
 
Last edited:
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
Add these lines after loading designer layout ;)

B4X:
Sub Activity_Create(FirstTime As Boolean)
   'Do not forget to load the layout file created with the visual designer. For example:
   Activity.LoadLayout("layMain")
   
   Dim bmp As Bitmap = LoadBitmap(File.DirAssets, "kingdiamonds.png")   
   pnlByDesigner.SetBackgroundImage(bmp)

   '*********ADD THESE 3 LINES*************
   Dim JO As JavaObject = pnlByDesigner
   Dim pos As Float = pnlByDesigner.Width/2
   JO.RunMethod("setPivotX",Array(pos))
   
   pnlByCode.Initialize("")
   Activity.AddView(pnlByCode, 0, 0, 150dip, 225dip)
   pnlByCode.SetBackgroundImage(bmp)
   
   InitAnimation
End Sub

It seems as if Views added by code have this pivot point set at its center (which is the default for Android) but the ones added by designer don't:eek:
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Almost perfect :)

It's enough for me but it's still not the same result. See the top (and bottom) of the card: the perspective is not correct, in the card added by designer (the middle one)

upload_2017-2-24_19-50-35.png


Anyway, double like to you, @JordiCP :)
 
Last edited:
Upvote 0

Informatix

Expert
Licensed User
Longtime User
Add these lines after loading designer layout ;)

B4X:
Sub Activity_Create(FirstTime As Boolean)
   'Do not forget to load the layout file created with the visual designer. For example:
   Activity.LoadLayout("layMain")
  
   Dim bmp As Bitmap = LoadBitmap(File.DirAssets, "kingdiamonds.png")  
   pnlByDesigner.SetBackgroundImage(bmp)

   '*********ADD THESE 3 LINES*************
   Dim JO As JavaObject = pnlByDesigner
   Dim pos As Float = pnlByDesigner.Width/2
   JO.RunMethod("setPivotX",Array(pos))
  
   pnlByCode.Initialize("")
   Activity.AddView(pnlByCode, 0, 0, 150dip, 225dip)
   pnlByCode.SetBackgroundImage(bmp)
  
   InitAnimation
End Sub

It seems as if Views added by code have this pivot point set at its center (which is the default for Android) but the ones added by designer don't:eek:
If NineOldAndroids is used, there's no need for JavaObject. You can set the pivot coordinates this way:
B4X:
Dim VH As noaViewHelper
VH.setPivotX(pnlByDesigner, pnlByDesigner.Width/2)
VH.setPivotY(pnlByDesigner, pnlByDesigner.Height/2)
 
Upvote 0
Top