Skip to content

Instantly share code, notes, and snippets.

@Gkemon
Created April 1, 2021 06:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gkemon/db4c2a6b6ab8a230b8c46ce20218bec9 to your computer and use it in GitHub Desktop.
Save Gkemon/db4c2a6b6ab8a230b8c46ce20218bec9 to your computer and use it in GitHub Desktop.
Rotate view by toggle
boolean isRotated= false;
View rotateLayout;
if(isRotated)
{
rotateLayout.setRotation(360);
rotateLayout.setTranslationX(0);
rotateLayout.setTranslationY(0);
ViewGroup.LayoutParams lp = rotateLayout.getLayoutParams();
lp.height = measuredHeight;
lp.width = measureWidth;
rotateLayout.requestLayout();
mSignatureView.setTranslationX(linearLayout.getLeft());
mSignatureView.setTranslationY(linearLayout.getTop());
ViewGroup.LayoutParams lp1 = mSignatureView.getLayoutParams();
lp1.height = measuredHeight;
lp1.width = measureWidth;
mSignatureView.requestLayout();
isRotated=false;
}
else {
rotateLayout.setRotation(-90);
rotateLayout.setTranslationX((measureWidth - measuredHeight) / 2);
rotateLayout.setTranslationY((measuredHeight - measureWidth) / 2);
ViewGroup.LayoutParams lp = rotateLayout.getLayoutParams();
lp.height = measureWidth;
lp.width = measuredHeight;
rotateLayout.requestLayout();
mSignatureView.setTranslationX(linearLayout.getLeft());
mSignatureView.setTranslationY(linearLayout.getTop());
ViewGroup.LayoutParams lp2 = mSignatureView.getLayoutParams();
lp2.height = measureWidth;
lp2.width = measuredHeight;
mSignatureView.requestLayout();
isRotated=true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment