Android ScaleAnimation doesn#39;t scale clickable area(Android ScaleAnimation 无法缩放可点击区域)
问题描述
我的布局结构如下:
线性布局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 无法缩放可点击区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Android ScaleAnimation 无法缩放可点击区域


- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01