Custom image rotation

imageView.SetRotation (theta) centers the view around the pivot point and rotates the image around this rotation by theta degrees, which is fine, but how can I rotate the image without first centering it around this rotation?

to clear my question, imagine a board and an image on it, what setRotation does is stick a pin in the middle of this image and rotate it, what I want is to select an axis - say, the image at the bottom left and then rotate it.

I hope my question is clear and available for solution!

thanks!

0
source share
1 answer

You can set a new anchor point using:

setPivotY(float pivotY); setPivotX(float pivotX); 

After that, the rotation will be done using the new pivot point set by the above methods.

- EDITED -

I used this method to add an ImageView to my layout.

 private ImageView addImageView(RelativeLayout mainLayout, int x, int y, int width, int height, OnClickListener onClickListener){ ImageView imageView = new ImageView(this); imageView.setAdjustViewBounds(false); RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); params.height = height; params.width = width; imageView.setLayoutParams(params); imageView.setScaleType(ImageView.ScaleType.FIT_XY); imageView.setImageDrawable(getResources().getDrawable(R.drawable.marker_red)); params.leftMargin = x - width/2; params.topMargin = y - height/2; imageView.setOnClickListener(onClickListener); mainLayout.addView(imageView); return imageView; } 

I called a method with the following parameters:

  ImageView imageView; imageView = addImageView(mainLayout, 200, 300, 200, 200, new OnClickListener() { @Override public void onClick(View v) { imageView.setPivotX(200); imageView.setPivotY(200); imageView.setRotation(45); } }); 

Finally, you just click on the image and the image rotates 45 degrees.

considers

+2
source

All Articles