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 7195393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:34:15+00:00 2026-05-28T20:34:15+00:00

I have a custom view where I use transformations. So far so good, function

  • 0

I have a custom view where I use transformations. So far so good, function like setRotationY(), setScaleX(), setTranslationY() or even getMatrix() work as expected, I’m able manipulate my view and it displays fine.
Where I hit the wall is that a number of function behave strangely after that. For example function like getHitRect() return totally weird values! This is not helping my touch events.

I tried to overload the function but it is still far from working especially when using rotation or scaling (Translation working fine through). I think this as something to do with the fact that the matrix is expressed in child coordinate, so how can I get it in parents coordinate?

@Override
    public void getHitRect(Rect outRect){

        RectF rect = new RectF(); 
        rect.top = (float) this.getTop(); 
        rect.bottom = (float) this.getBottom(); 
        rect.left = (float) this.getLeft(); 
        rect.right = (float) this.getRight();      

    this.getMatrix().mapRect(rect);
        rect.round(outRect);
    }

Can I get some straighter value directly from some function? Like the new Height, Width, top or bottom.

  • 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-28T20:34:16+00:00Added an answer on May 28, 2026 at 8:34 pm

    When overriding the “getChildStaticTransformation” method of the ViewGroup or even using transformation function like setRotationY(), setScaleX(), setTranslationY(), getMatrix() (available from API 11) you are only affecting the rendering Matrix. As a result your custom Child View will return Bounds “Rects” far from where your child is getting draw. This is not an issue most of the time but when you start to be willing to click on it.. trouble are starting… Here is how I workaround the issue. I’m sure there might be a better ways but as I haven’t found many things on the subject here it is.

    In the ViewGroup Overload:

    public interface Itransformable {
        public void setTransformationMatrix(Matrix trsMatrix);
    }
    
    @Override
    protected boolean getChildStaticTransformation(View child, Transformation t) {
        if (child instanceof Itransformable){   
            t.clear();
            t.setTransformationType(Transformation.TYPE_MATRIX);
            ...
            // Do whatever transformation you want here
            ...
            ((Itransformable)child).setTransformationMatrix(t.getMatrix());
            return true;
        } else {
            return false;
        }
    }
    

    Here is the Child Custom View:
    Note that I’m not storing directly the Transformation Matrix in the custom view but instead the transformed Rect. If you want to go for storing the matrix (i.e. for later transformation like point…) you might need to clone it as the matrix will get altered in some strange way like it is recycle or something.

    public class MyCustomView extends View implements MyViewGroup.Itransformable{
    
    private Rect mViewRect = null;
    
    public void setTransformationMatrix(Matrix trsMatrix){
        if (trsMatrix!=null){
            RectF rect = new RectF();
            rect.top = 0;
            rect.bottom = (float) this.getHeight(); 
            rect.left = 0; 
            rect.right = (float) this.getWidth();  
    
            trsMatrix.mapRect(rect);
            rect.offset((float) this.getLeft(), (float) this.getTop());
    
            if (mViewRect == null) mViewRect = new Rect();
            rect.round(mViewRect);
        }
    }
    
    public Rect getTransformatedRect() {
        if (mViewRect!=null){
            // OutOfScreen WorkArround - As the view is not Displayed, mViewRect doesn't get updated.
            if(getRight() < 0 || getLeft() > mParentWidth){
                return new Rect(getLeft(),getTop(),getRight(),getBottom());
            } else {
                return mViewRect;
            }
        } else {
            return new Rect(getLeft(),getTop(),getRight(),getBottom());
        }
    }
    
    @Override
    public void getHitRect(Rect outRect){
    
        if (mViewRect == null){
            super.getHitRect(outRect);
        } else {
            outRect.set(getTransformatedRect());
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a listview with 200 items. I use a custom view for each
I have a custom-made view that extends the View class. I would like 2
I have a custom View that I'd like to specify the layout of in
I have a custom view in a .xib file, which I use as the
I have a custom view (which extends GLSurfaceView) I'm trying to use in my
I have a custom view that I would like to create from a resource
I have a custom view subclassed from GridView that I use in order to
We are using Plone 4.1, and would like to have a custom view of
I have created a custom UIView that I would like to use on multiple
I have a custom view which I would like to look like a UINavigationBar.

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.