简体   繁体   English

确定viewpager页面内的视图上的触摸

[英]determine touch on a view inside viewpager page

I have some pages which is loading into viewpager. 我有一些页面加载到viewpager。 I want to determine if there any way to find out if user touch the view(inside page) when the page is visible? 我想确定是否有任何方法可以确定用户是否在页面可见时触摸视图(内页)? My view pager page view is something like this Basic1.java and initshape() method as describe . 我的查看分页器页面视图类似于此描述的Basic1.java和initshape()方法 Please let me know any more information is required. 请让我知道需要更多信息。

implement following code in a page(fragment) you want to detect touch event. 在要检测触摸事件的页面(片段)中实现以下代码。

@Override
 public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
// Inflate the layout containing a title and body text.
ViewGroup rootView = (ViewGroup) inflater
                .inflate(R.layout.fragment_slide, container, false);
LinearLayout layout = (LinearLayout)rootView.findViewById(R.id.layout)// get your root  layout
layout.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            Log.v(null, "TOUCH EVENT"); // handle your fragment touch  here
            return false;
        }
    });
      return rootView;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM