2017-04-12 97 views
2

我遇到问题。Android:clipChildren = false和onClickListner用于修剪儿童

我们有布局定制框架布局,缩放和平移功能

public class MyFrameLayout extends FrameLayout { 
... 
@Override 
protected void onDraw(Canvas canvas) { 
    super.onDraw(canvas); 

    getChildAt(0).setTranslationX(vTranslate.x); 
    getChildAt(0).setTranslationY(vTranslate.y); 
    getChildAt(0).setScaleX(mScale.scaleFactor); 
    getChildAt(0).setScaleY(mScale.scaleFactor); 
} 

类侦听触摸手势和翻译/扩展自己的孩子。 我用它作为ViewGroup内容的父视图组。

<MyFrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@color/gray" 
android:clipChildren="false"> 

<android.support.constraint.ConstraintLayout 
    android:id="@+id/calc_constraint_layout" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:clipChildren="false"/> 

内容约束布局programmaticaly增加,这是更大然后屏幕或父组。正因为如此,我们设置了clipChildren = false。 但是,在转换之前出界的孩子不会对onClick事件做出回应。

一些照片:

开始屏幕enter image description here

翻译后: enter image description here

6%的节点只是不回答点击。 请帮帮我。

地址: enter image description here

+0

那么'MyFrameLayout'和'ConstraintLayout'的宽度是多少? – pskink

+0

@pskink它是match_parent。如果我为约束布局设置宽度为2000dp(白色) - 容器将变大并点击工作。不知道,为什么match_parent和wrap_content都不适用于约束布局。它仍然具有“屏幕大小” – Kotsu

+0

所以你可以看到事件传递给子视图,如果event(x,y)位置在父级内部 - 如果它位于父级之外,则简单地忽略它们 - 可能不是“ setTranslation *'方法你可以尝试'scrollTo' /'scrollBy' - 我不知道它如何与'setScale *'一起工作... – pskink

回答

0

嘛。我无法找到约束布局(白色)以适应wrap_content值的内容。我的解决方法是动态增加约束布局的宽度和高度,从而相应地增加节点树的宽度和高度。

当你添加额外的节点 - 布局度量增长,你看它如何调整abit。然后为了解决这个问题,我不得不在父级布局中重写onLayout()方法(它在屏幕截图上是绿色的,但它是自定义的ZoomableLayout)。

现在一切正常。但我不确定这个实现是否丑陋。