Android ScaleAnimation doesn't scale clickable area

牧云@^-^@ 提交于 2019-11-29 10:19:37

问题


I have a layout structured as follows:

LinearLayout1
    LinearLayout2
        EditText

I am applying a ScaleAnimation to LinearLayout1 using a LayoutAnimationController so that all of the views in the hierarchy are scaled by the same amount.

After applying the ScaleAnimation, the views are all scaled correctly, but the EditText no longer responds to clicks that fall outside the space it originally occupied. In other words, it appears that the clickable area for the EditText does not scale along with the visual representation.

Is there a solution to this problem or I am missing before or after calling the ScaleAnimation?


回答1:


In case anyone else is looking for the answer to this problem, here is the solution I came up with. I capture click events in LinearLayout1 and do a manual recursive hit test down the view hierarchy using getHitRect and applying the scaling factor to the dimensions received.

Here is my implementation of the hit test for a view.

public boolean scaledHitTest(float zoomScale, int x, int y) {
        Rect rect = new Rect();
        getHitRect(rect);
        rect.top = (int) (rect.top * zoomScale);
        rect.bottom = (int) (rect.bottom * zoomScale);
        rect.left = (int) (rect.left * zoomScale);
        rect.right = (int) (rect.right * zoomScale);

        return rect.contains(x, y);
}


来源:https://stackoverflow.com/questions/5808234/android-scaleanimation-doesnt-scale-clickable-area

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!