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
Luis
source share