问题描述
我的布局结构如下:
线性布局1
线性布局2
编辑文本
LinearLayout1
LinearLayout2
EditText
我正在使用 LayoutAnimationController 将 ScaleAnimation 应用到 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.
应用 ScaleAnimation 后,所有视图都正确缩放,但 EditText 不再响应落在其最初占用空间之外的点击.换句话说,EditText 的可点击区域似乎没有随着视觉表示而缩放.
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 无法缩放可点击区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!