【问题标题】:get click position on surfaceview and show dialog获取surfaceview上的点击位置并显示对话框
【发布时间】:2014-10-27 08:52:13
【问题描述】:

我想从 surfaceview 中点击 x 和 y 并在同一活动中显示对话框。

点击监听器不适用于surfaceview。

我正在使用android pdfview 库来显示pdf 文档,它正在使用surfaceview 来查看PDF 页面。

https://github.com/JoanZapata/android-pdfview

另外,当我尝试获取表面视图的绘图缓存时,它会返回黑色视图。

     final AlertDialog.Builder addSing = new AlertDialog.Builder(PDFViewActivity.this);

       addSing.setTitle("Do you want to add Signature here ?");
       addSing.setCancelable(false);

       addSing.setPositiveButton("Yes", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub


            }
       });

       addSing.setNegativeButton("No", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub

           }
       });


    PDFViewActivity.this.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            // TODO Auto-generated method stub



               addSing.show();



        }
    });

【问题讨论】:

    标签: android pdf surfaceview


    【解决方案1】:

    开始点击表面视图:

    为了获得点击表面视图实现 onTouchListener 和 GestureDetector :

    @Override
        public boolean onTouch(View v, MotionEvent event) {
    
            mGestureDetector.onTouchEvent(event);
    
            switch (event.getAction() & MotionEvent.ACTION_MASK) {
    
            case MotionEvent.ACTION_DOWN:
                if (mInputListener != null)
                    mInputListener.onTouchDown(new Vector2(event.getX(), event
                            .getY()));
                break;
    
            case MotionEvent.ACTION_MOVE:
                if (mInputListener != null)
                    mInputListener.onTouchMove(new Vector2(event.getX(), event
                            .getY()));
                break;
    
            case MotionEvent.ACTION_UP:
                if (mInputListener != null)
                    mInputListener
                            .onTouchUp(new Vector2(event.getX(), event.getY()));
                break;
            }
    
            return true;
        }
    
        private class GestureListener extends
                GestureDetector.SimpleOnGestureListener {
    
            @Override
            public boolean onDoubleTap(MotionEvent e) {
                if (mInputListener != null)
                    mInputListener.onDoubleTap(new Vector2(e.getX(), e.getY()));
                return super.onDoubleTap(e);
            }
    
            @Override
            public boolean onSingleTapConfirmed(MotionEvent e) {
                if (mInputListener != null)
                    mInputListener.onSingleTapConfirmed(new Vector2(e.getX(), e
                            .getY()));
                return super.onSingleTapConfirmed(e);
            }
    
            @Override
            public boolean onSingleTapUp(MotionEvent e) {
                if (mInputListener != null)
                    mInputListener.onSingleTap(new Vector2(e.getX(), e.getY()));
                return super.onSingleTapUp(e);
            }
    
        }
    

    有关更多信息,请参阅this

    IInd SurfaceView 绘图缓存:来自this answer

    IIIrd 显示对话框:我认为您的代码可以很好地显示对话框。

    抱歉,SurfaceView 本质上不会在普通视图中绘制 层次更新系统,所以不会画在里面。

    【讨论】:

      猜你喜欢
      • 2022-08-19
      • 2018-04-04
      • 2014-04-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多