机器人如何注册的onTouchEvent为整个活动的主要内容有何看法? [英] Android How to register OnTouchEvent for entire Activity main content view?
问题描述
我已经在我的活动实现的onTouchEvent(的TouchEvent)。不过,我想知道需要哪些步骤来注册此作为事件的主要活动内容视图。我想设置的onTouchEvent的,涵盖了活动的整个屏幕空间的观点。有一个的setContentView(),这需要布局ID。如何注册活动为的onTouchEvent监听的主要内容视图。我正在考虑findByView(activityLayoutId)得到这个观点,但是这似乎并不很喜欢的权利或最佳方式。谢谢
I have implemented onTouchEvent(TouchEvent) on my activity. However, I would like to know what steps are required to register this as the event for the activities main Content view. I want to set the onTouchEvent for the view that covers the entire screen space of the activity. there is a setContentView() which takes a layout id. How do I register the activity as the ontouchEvent listener to the main content view. I am considering findByView(activityLayoutId) to get this view, but this does not seem quite like the right or best way. Thanks
推荐答案
如果你正在寻找一种方法之后活动#的setContentView(INT)$ C,让您的内容视图以查看
If you're looking for a way to get your content view as a View after Activity#setContentView(int)
, then you can set an id on the outer-most element of your layout:
android:id="@+id/entire_view"
和后的setContentView
引用它在你的的onCreate
方法:
and reference it in your onCreate
method after setContentView
:
View view = getViewById(R.id.entire_view);
view.setOnTouchListener( ...
这篇关于机器人如何注册的onTouchEvent为整个活动的主要内容有何看法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!