【问题标题】:determine touch on a view inside viewpager page确定对 viewpager 页面内视图的触摸
【发布时间】:2016-04-02 06:30:58
【问题描述】:

我有一些页面正在加载到 viewpager 中。我想确定是否有任何方法可以确定用户在页面可见时是否触摸了视图(页面内)?我的视图寻呼机页面视图类似于Basic1.java and initshape() method as describe。 如果需要更多信息,请告诉我。

【问题讨论】:

    标签: android view touch motionevent motion-detection


    【解决方案1】:

    在要检测触摸事件的页面(片段)中实现以下代码。

    @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;
        }
    

    【讨论】:

    • 会尝试让你知道结果。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多