Android Question Create shape with Path

noclass1980

Active Member
Licensed User
Longtime User
Hi,

I use the Path functionality to define a shape (a hexagon) and then use ClipPath to assign a bitmap to the defined path (to create a textured look. Is it possible to use the created shape as a discrete object that can be rotated, flipped and moved about the screen? In other words, create that hexagon at some point on the screen at run time and then move it to another location as an animation.
Thanks in advance
 

klaus

Expert
Licensed User
Longtime User
I suggest you to use a transparent ImageView or Panel, draw the hexagon onto it and then you can move and rotate it, rotation will need the Reflection library.
Or you could use a transparent Panel covering the whole screen and draw the hexagone where you want, to erase the previous hexagon draw a transparent one at it's position.
 
Upvote 0

noclass1980

Active Member
Licensed User
Longtime User
Ok, thanks, I'll try that.
 
Upvote 0

noclass1980

Active Member
Licensed User
Longtime User
Hi Klaus, I'vve had a look at the reflection library but don't know which methods to use. The code below draws (on Panel1 with PanelCanvas on it) the shape previously defined by XPath1 and puts the texture Xsurface on it. How do I then rotate the panel by 60 degrees and move it from X1,Y1 to X2Y2? Thanks

B4X:
PanelCanvas.DrawPath(XPath1,Colors.White, True, 1dip)
PanelCanvas.ClipPath(XPath1)
PanelCanvas.DrawBitmap(Xsurface,Null,DestRect)
Activity.Invalidate

Thanks in advance
 
Upvote 0

noclass1980

Active Member
Licensed User
Longtime User
Hi, I developed a work around for my last post above (#4) using the AnimationPlus libary as below. In terms of resources, is this more expensive than using the Reflection library. I'd appreciate it if anyone can advise and also provide the reflection code to achieve the rotation. Thanks in advance.

B4X:
Dim ani as AnimationPlus
ani.InitializeRotatecenter("ani",0,45, Panel1)
'ani.Duration=2000 if the duration isn't set then the animation is instantaneous
ani.Start(Panel1)
ani.PersistAfter=True
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
The Reflection routine to rotate a view :
B4X:
'Sets the rotation angle of the given view
Sub setRotation(v As View, a As Float)
    refl.Target = v
    refl.RunMethod2("setRotation", a, "java.lang.float")
End Sub
Attached a small demo program.
 

Attachments

  • RotatePanel.zip
    7.1 KB · Views: 216
Upvote 0

noclass1980

Active Member
Licensed User
Longtime User
Many thanks, Klaus, very helpful as always!
 
Upvote 0
Top