检测双击(双击)或长按在videoview [英] detect double tap (Double click) or long click in a videoview

查看:1557
本文介绍了检测双击(双击)或长按在videoview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个Android应用程序。在我的应用我要显示视频的screen.Then的角落。如果用户双击或longclicked我必须展开视频全屏。
所以我用下面的code。

I am working on an Android application. In my app I have to show the video in the corner of the screen.Then If the user double clicked or longclicked I have to expand the video in to full screen. So i used the following code.

vd.setOnLongClickListener(new OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            // TODO Auto-generated method stub




            if (!flag) {
                DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics);
                android.widget.LinearLayout.LayoutParams params = (android.widget.LinearLayout.LayoutParams) vd.getLayoutParams();
                params.width =  metrics.widthPixels;
                params.height = metrics.heightPixels;
                params.leftMargin = 0;
                vd.setLayoutParams(params);
                flag=true;

            }
            else{

                DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics);
                android.widget.LinearLayout.LayoutParams params = (android.widget.LinearLayout.LayoutParams) vd.getLayoutParams();
                params.width =  (int) (200);
                params.height = (int) (200);
                params.leftMargin = 30;
                vd.setLayoutParams(params);
                flag = false;

            }
            return true;
        }

    });

但没有happeneds在长click.Long点击工作正常的按钮,但不是Videoview。请帮我找到一个解决方案。
在此先感谢

But nothing happeneds on the long click.Long click is working fine for button but not for Videoview. Please help me to find a solution. Thanks in advance

推荐答案

更​​正确的做法:
设置监听器:

More right way: set listener:

videoView.setOnTouchListener(new OnTouchListener () {
    @Override
    public boolean onTouch(View v, MotionEvent event) {

        if(event.getAction() == MotionEvent.ACTION_DOWN && longClickTimer == null)
        {
            if (mc.isShowing()) {mc.hide();} else {
                mc.show(10000);} 
            longClickTimer = new Timer();
            longClickTimer.schedule(new longClickTask(), 3000);
        }
        else 
        {
            if(longClickTimer != null)
            {
                longClickTimer.cancel();
                longClickTimer.purge();
                longClickTimer = null;
            }
        }
        return true;
    }});

任务定时器:

class longClickTask extends TimerTask {
    @Override
    public void run() {

        if(longClickTimer != null)
        {
            longClickTimer.cancel();
            longClickTimer.purge();
            longClickTimer = null;
        }
        getActivity().runOnUiThread(Runnable1);
    }}

和可运行全屏:

final Runnable Runnable1 = new Runnable() {
    public void run() {
        int orien = getResources().getConfiguration().orientation;
        if ((orien==Configuration.ORIENTATION_LANDSCAPE) && (frag==0)) {
        if (fullscr==false) { 
        wind.clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
        wind.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        DisplayMetrics metrics = new DisplayMetrics(); wind.getWindowManager().getDefaultDisplay().getMetrics(metrics);
        android.widget.FrameLayout.LayoutParams params = (android.widget.FrameLayout.LayoutParams) videoView.getLayoutParams();
        heightvid=params.height;
        params.width =  metrics.widthPixels;
        params.height = metrics.heightPixels;
        frame1.setBackgroundColor(Color.BLACK);

        videoView.setLayoutParams(params);
        fullscr=true;}
        else if ((orien==Configuration.ORIENTATION_LANDSCAPE) && (frag==0)) {
            wind.setFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN, WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
            DisplayMetrics metrics = new DisplayMetrics(); wind.getWindowManager().getDefaultDisplay().getMetrics(metrics);
            android.widget.FrameLayout.LayoutParams params = (android.widget.FrameLayout.LayoutParams) videoView.getLayoutParams();
            params.width =  WindowManager.LayoutParams.FILL_PARENT;
            params.height = heightvid;
            frame1.setBackgroundColor(Color.WHITE);

            videoView.setLayoutParams(params);
            fullscr=false;
        }
    }}
};

享受!

这篇关于检测双击(双击)或长按在videoview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆