問題描述
我的布局結構如下:
線性布局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 無法縮放可點擊區域的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!