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 无法缩放可点击区域
基础教程推荐
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01