Android的ScaleAnimation不能扩展可点击区域 [英] Android ScaleAnimation doesn't scale clickable area

查看:311
本文介绍了Android的ScaleAnimation不能扩展可点击区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个布局结构如下:

I have a layout structured as follows:

LinearLayout1
    LinearLayout2
        EditText

LinearLayout1
    LinearLayout2
        EditText

我使用的是LayoutAnimationController使所有的层次结构中的观点是相同的量缩放应用Sca​​leAnimation到LinearLayout1。

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.

应用Sca​​leAnimation后,意见都是按比例正确,但EditText上不再响应落在它原来占用的空间以外的点击。换句话说,似乎可点击区域的的EditText不与视觉重新presentation缩放沿

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.

有没有解决这个问题,或者我之前或致电ScaleAnimation后失踪?

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

推荐答案

在情况下,任何人都正在寻找的答案,这个问题,这里是我想出了一个解决方案。我捕捉LinearLayout1点击事件,做手工递归命中测试下来使用getHitRect和应用的缩放因子收到的维度视图层次结构。

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);
}

这篇关于Android的ScaleAnimation不能扩展可点击区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆