单击整个屏幕

时间:2018-02-19 16:42:41

标签: screen onclicklistener

我有一个项目需要在整个屏幕上设置点击监听器(点击屏幕时我会收集加速度计的值)。

我只能在任何地方看到我需要设置一个按钮(不能没有按钮吗?),它可以是透明的,与屏幕尺寸相同。是否有其他可能性或OnClickListener仅在使用按钮时才有效?

我希望我已经足够可以理解了。

2 个答案:

答案 0 :(得分:0)

如果您在android(听起来像),请转到xml视图代码并添加android:onClick ="单击时调用的方法"。转到活动代码并添加您分配给onClick属性的方法。

xml查看代码:

@Autowired
JsonViewTemplateEngine templateEngine

void myMethod() {
    Template t = templateEngine.resolveTemplate('/book/show')
    def writable = t.make(book: new Book(title:"The Stand"))
    def fw = new FileWriter(...)
    writable.writeTo( fw )
    ...
}

然后在活动代码中:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/layout"
    android:background="@drawable/tempback"
    android:onClick="clickListener"

    >

答案 1 :(得分:0)

这是我做的:

1)在我的xml视图代码中,我检查了布局的名称,其中包括所有其他的“ConstraintLayout”

<android.support.constraint.ConstraintLayout

xmlns:android="http://schemas.android.com/apk/res/android"

//Other layouts

>

2)然后我在实现View.OnTouchListener:

之后在我的活动中添加它

((ConstraintLayout) findViewById(R.id.layout_main)).setOnTouchListener(this);

@Override

public boolean onTouch(View view, MotionEvent motionEvent) {

//DO THINGS


return false;

}

相关问题