Android - 多点触控 - 在View上点击后无法捕获ACTION_POINTER_DOWN

时间:2013-01-02 09:16:20

标签: android multi-touch

我有这样的布局 -

     <RelativeLayout   
        android:id="@+id/relativeLayoutTable"   
        android:layout_height="fill_parent"     
        android:layout_width="fill_parent"       
        android:layout_below="@+id/relativeLayout215"
        android:layout_toRightOf="@+id/relativeLayout20" >

            <ScrollView 
                android:id="@+id/scrollView" 
                android:layout_height="fill_parent"     
                android:layout_width="fill_parent"         
                android:scrollbars="horizontal|vertical" 
                android:fillViewport="true"
                android:scrollbarStyle="insideOverlay"> 

                <HorizontalScrollView
                    android:id="@+id/horizontalScrollView1"  
                    android:layout_width="wrap_content"  
                    android:layout_height="wrap_content"
                    android:scrollbarStyle="insideOverlay" >

                    <TableLayout
                        android:id="@+id/tableLayout1"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:gravity="center" />
                </HorizontalScrollView>
        </ScrollView>
    </RelativeLayout>

tablelayout由以编程方式创建的单元格/视图组成。我为每个单元格/视图定义了onClicklistener。现在,我还为scrollView定义了onTouchlistener。我可以获取单元格/视图的单击事件,但是我没有在scrollView上获得ACTION_POINTER_DOWN事件。请帮忙。感谢。

1 个答案:

答案 0 :(得分:0)

如果删除onClicklistener,则拖动/ onTouchlistener表格布局就可以了 你可以尝试代码,它适合我:

    @Override
public boolean onInterceptTouchEvent(MotionEvent event) {
    boolean intercept = false;
    switch (event.getAction()  & MotionEvent.ACTION_MASK ) {
        case MotionEvent.ACTION_DOWN: {
            currentX = (int) event.getRawX();
            currentY = (int) event.getRawY();
            break;
        }
        case MotionEvent.ACTION_MOVE: {
            int x2 = Math.abs(currentX - (int) event.getRawX());
            int y2 = Math.abs(currentY - (int) event.getRawY());
            if (x2 > touchSlop || y2 > touchSlop) {
                intercept = true;
            }
            break;
        }
        case MotionEvent.ACTION_POINTER_DOWN: {//it's important
            oldDist = spacing(event);
            mode = ZOOM;
            intercept = true;
            break;
        }
    }
    return intercept;
}