如何为存在视图设置我的动作侦听器

How to set my motion listener for exist view

例如,为 VideoView 添加双击侦听器。我希望它支持以下代码:

//Player.kt
var vv = findViewById(R.id.player) as VideoView
vv.onDoubleClick {
  // do something
}

I hope it support following code:
...

很可能您在此处显示的语法受到 Anko 库的启发,该库具有一些扩展功能,允许您以这种漂亮的方式添加 View 侦听器:

button.onClick {
    Toast.makeText(this, "Hi there!", Toast.LENGTH_SHORT);
}

而不是冗长的 Java 语法:

button.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Toast.makeText(this, "Hi there!", Toast.LENGTH_LONG).show();
    }
});

不幸的是,Anko 没有onDoubleClick 扩展功能(好吧,View 也没有setOnDoubleClickListener() 方法)。如果要为视图添加 double-click 支持,则需要使用 GestureDetectors. And, if you wish to write this code with the help of extensions functions, like in Anko, documentation can be found here.