Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6733413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:45:56+00:00 2026-05-26T10:45:56+00:00

I use the following class to create a rotatable dialog and everything is ok.

  • 0

I use the following class to create a rotatable dialog and everything is ok.

import android.content.Context;

import android.graphics.Canvas;
import android.graphics.Matrix;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.LinearLayout;

public class RotateLinearLayout extends LinearLayout {

private Matrix mForward = new Matrix();
private Matrix mReverse = new Matrix();
private float[] mTemp = new float[2];
private float degree = 0;

public RotateLinearLayout(Context context) {
    super(context);
}

public RotateLinearLayout(Context context, AttributeSet attrs) {
    super(context, attrs);
}

@Override
protected void dispatchDraw(Canvas canvas) {
    if (degree == 0) {
        super.dispatchDraw(canvas);
        return;
    }
    canvas.rotate(degree, getWidth() / 2, getHeight() / 2);
    mForward = canvas.getMatrix();
    mForward.invert(mReverse);
    canvas.save();
    canvas.setMatrix(mForward); // This is the matrix we need to use for
                                // proper positioning of touch events
    super.dispatchDraw(canvas);
    canvas.restore();
}

@Override
public boolean dispatchTouchEvent(MotionEvent event) {
    if (degree == 0) {
        return super.dispatchTouchEvent(event);
    }
    final float[] temp = mTemp;
    temp[0] = event.getX();
    temp[1] = event.getY();

    mReverse.mapPoints(temp);

    event.setLocation(temp[0], temp[1]);
    return super.dispatchTouchEvent(event);
}

public void rotate() {
    if (degree == 0) {
        degree = 180;
    } else {
        degree = 0;
    }
}
}

I have an ImageView on left side of this dialog which is equipped with an animation. When the dialog is not rotated ImageView animates correctly. When I rotate my dialog, ImageView must animate on right side of dialog but it changes the screen pixels of previously placed ImageView in an ugly state. I mean after rotation the position of ImageView changes correctly but the position of its animation remains unchanged.

How can I set the new position of ImageView’s animation?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T10:45:57+00:00Added an answer on May 26, 2026 at 10:45 am

    I just added the line invalidate(); and everything was corrected:

        @Override
    protected void dispatchDraw(Canvas canvas) {
        if (degree == 0) {
            super.dispatchDraw(canvas);
            return;
        }
        canvas.rotate(degree, getWidth() / 2, getHeight() / 2);
        mForward = canvas.getMatrix();
        mForward.invert(mReverse);
        canvas.save();
        canvas.setMatrix(mForward); // This is the matrix we need to use for
                                    // proper positioning of touch events
        super.dispatchDraw(canvas);
        canvas.restore();
        // is needed
        invalidate();
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I will use (again) the following class hierarchy: Event and all the following classes
In Ruby 1.9, I can use its class variable like the following: class Sample
I use the following function to show controls on my form: class procedure TFormMain.FadeControls(ctrl:Array
I have the following use case: There's a class called Template and with that
Consider the following use of template template parameters... #include <iostream> template <typename X> class
I use the following: public interface IRepository<T> { void Add(T entity); } public class
Please consider the following simple use case: public class Foo { public virtual int
I have following code snippet that i use to compile class at the run
I'm working with java, trying to use the AudioFormat Class. I have the following
I currently use the following approach to create a strongly typed object representing session

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.