0

在此处输入图像描述你好,当用户点击带有显示值的 achartengine 点时,我想显示祝酒词。我正在尝试使用 toScreenPoint 方法获取屏幕位置值,但是如果我平移屏幕(移动图表)之后它会给出正确的屏幕点并将这个值设置为 Toast,它会给出错误的值。我的代码如下所示。

       chart=new TimeChart(dataset, charthelper.getXYMultipleSeriesRenderer());
           graphview.setOnClickListener(new OnClickListener() { 
        @Override
        public void onClick(View v) {
            SeriesSelection ss=graphview.getCurrentSeriesAndPoint();
              if (ss == null) {
                  } else {

                double[] screenPoint = chart.toScreenPoint(new double[] {
                        ss.getXValue(),ss.getValue() },0);
                toast_textview.setText(ss.getValue()+"");
                Toast toast=new Toast(getApplicationContext());
                toast.setGravity(Gravity.TOP|Gravity.LEFT, (int)screenPoint[0],(int)screenPoint[1]);
                toast.setView(toast_layout);
                toast.show();       
                  }
                }
    });
    container_layout.addView(graphview,0);

[更新] 我用这种方式解决了

 /**
     * set ontouch listener for double tap
     */
    graphview.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            x = event.getX();
            y = event.getY();
            detector.onTouchEvent(event);
            detector.setIsLongpressEnabled(true);
            return false;
        }
    });
    graphview.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            SeriesSelection ss = graphview.getCurrentSeriesAndPoint();
            if (ss == null) {
            } else {
                /**
                 * toast display only series of value which index is
                 * zero
                 */
                if (ss.getSeriesIndex() == 0) {
                    toast_textview.setText(ss.getValue() + "");
                    Toast toast = new Toast(getApplicationContext());
                    DecimalFormat formatter = new DecimalFormat("##.##");
                    toast_textview.setText(formatter.format(ss.getValue()) + "");
                    toast.setGravity(Gravity.TOP | Gravity.LEFT, (int) x,
                            (int) y);
                    toast.setView(toast_layout);
                    toast.setDuration(Toast.LENGTH_SHORT);
                    toast.show();
                }
            }
        }
    });
4

0 回答 0