需要识别不同元素上方的手势(例如桌面上的行,按钮等)

时间:2012-07-25 17:13:22

标签: android gesture gesture-recognition

我需要像这样识别xml上的手势:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:id="@+id/main_1"
             android:gravity="center"> 
</TableLayout>

在我的活动中,在表格中添加一些行:

private void buildField() {
    Square[][] field = game.getField();
    for (int i = 0, lenI = field.length; i < lenI; i++ ) {
        TableRow row = new TableRow(this); 
        for (int j = 0, lenJ = field[i].length; j < lenJ; j++) {
            Button button = new Button(this);
            buttons[i][j] = button;
            button.setOnClickListener(new Listener(i, j)); 
            row.addView(button, new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,
                    TableRow.LayoutParams.WRAP_CONTENT));
            button.setWidth(107);
            button.setHeight(107);
        }
        layout.addView(row, new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT,
                TableLayout.LayoutParams.WRAP_CONTENT)); 
    }
}

当用户在该行上绘制手势时,如何在按钮上触发setOnClickListener?

1 个答案:

答案 0 :(得分:0)

GestureOverlayView自动处理此问题。有关帮助您入门的教程,请参阅here