Android Question Make panel in different shape

jazzzzzzz

Active Member
Licensed User
Longtime User
I want to make different panel in shape of parallelogram and put a image in background or an imageview in a shape of paralellogram..how can i do it?
 

Cableguy

Expert
Licensed User
Longtime User
You cannot change thé shape of an activity, what you can do is to set its background color to transparent and then ad an image view with the image in the shape or your choice.
 
Upvote 0

jazzzzzzz

Active Member
Licensed User
Longtime User
that works just by cropping the image,its not practical in my case.I need the whole view to be tilt in a small angle
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
Try this

B4X:
Sub rotateImageView( myIV as ImageView)
  Dim JJ as JavaObject = myIV 
  Dim mRotation as float=45
  JJ.runMethod("setRotation",Array(mRotation))
End Sub
 
Upvote 0

jazzzzzzz

Active Member
Licensed User
Longtime User
@JordiCP That code worked but I need imageView to be rotated and image in horizontal..;(

@klaus What I need is to make the container of imageView as a parallelogram i have attached a sample design
 

Attachments

  • Untitled.png
    Untitled.png
    417.4 KB · Views: 176
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
If you want to keep the image horizontal, then you don't want to rotate the imageview, but its borders.

A way to do it would be to use canvas to draw the desired bitmap into an imageview using clippath to define these "custom" borders

For instance,
B4X:
    IV.Initialize("IV")
    IV.Gravity=Gravity.FILL
    Dim WW As Int = 100%X
    Dim HH As Int = 100%Y
    Activity.AddView(IV,50%X-WW/2,50%Y-HH/2,WW,HH)

    Dim c As Canvas
    c.Initialize(IV)
    Dim cp As Path
    cp.Initialize(0,0)
    cp.LineTo(100%X,0)
    cp.LineTo(100%X,40%Y)
    cp.LineTo(0%X,60%Y)
    cp.LineTo(0,0)
    c.ClipPath(cp)
    Dim dstRect As Rect
    dstRect.Initialize(0,0,100%X,60%Y)
    c.DrawBitmap(LoadBitmap(File.DirAssets,"a.jpg"),Null,dstRect)
   
    c.RemoveClip
    cp.Initialize(0,60%Y)
    cp.LineTo(100%X,40%Y)
    cp.LineTo(100%X,100%Y)
    cp.LineTo(0%X,100%Y)
    cp.LineTo(0,60%Y)
    c.ClipPath(cp)
    Dim dstRect As Rect
    dstRect.Initialize(0,40%Y,100%X,100%Y)
    c.DrawBitmap(LoadBitmap(File.DirAssets,"b.jpg"),Null,dstRect)


@klaus: I have just seen THIS, missed when you posted it (would have saved me several hours ;))
 

Attachments

  • scs.png
    scs.png
    460 KB · Views: 169
Upvote 0

jazzzzzzz

Active Member
Licensed User
Longtime User
Idea is Perfect..but the image comes in Gravity Filled ,How can i make gravity centerd in each Clip
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
playing with the srcRect (in the example set to Null, so the whole bitmap was got, but you can change it ) and dstRec coordinates, any gravity effect can be achieved

Anyway, this method "crops" a bit the bitmaps and is good for composing. If what you want is to "fill" the whole clip area with the bitmap (deforming it), I guess you would have to use other methods. But the picture you attached seems to be only "cropped"
 
Upvote 0
Top