2014-09-10 37 views
0

你好,我想問一下,我怎麼能在圖像顯示吐司附近的用戶點擊點像下面使用GraphView庫:GraphView如何顯示吐司用戶點擊點附近

http://android-graphview.org/

enter image description here

感謝您的任何意見

編輯:

我嘗試了用

seriesSin = new GraphViewSeries("Sinus curve", new GraphViewSeries.GraphViewSeriesStyle(Color.rgb(200, 50, 00), 3), data); 

    // SET ON TOUCH 
     graphView.setOnTouchListener(new View.OnTouchListener(){ 
      public boolean onTouch(View v, MotionEvent event) { 
       if(event.getAction() == MotionEvent.ACTION_DOWN) { 
        int size = seriesSin.size(); 
        float screenX = event.getX(); 
        float screenY = event.getY(); 
        float width_x = v.getWidth(); 
        float viewX = screenX - v.getLeft(); 
        float viewY = screenY - v.getTop(); 
        float percent_x = (viewX/width_x); 
        int pos = (int) (size*percent_x); 

        System.out.println("X: " + viewX + " Y: " + viewY +" Percent = " +percent_x); 
        System.out.println("YVal = " +seriesSin.getY(pos)); 
        return true; 
       } 
       return false; 
      } 

     }); 

但我不能讓seriesSin.size和seriesSin.getY(POS)

+1

棘手。你可以試一試'toast.setGravity(Gravity.TOP | Gravity.LEFT,x,y);'[touch of position](http://stackoverflow.com/a/23411401/1777090) – 2014-09-10 12:56:00

+0

你好,感謝您的回覆,請參閱我的更新問題.. – redrom 2014-09-10 13:05:51

+0

任何崩潰或只是獲得空值? – 2014-09-10 13:08:26

回答

0

你不能決定在哪裏顯示Toast。但是,您可以設置自定義視圖並使用您在檢測觸摸時獲得的座標(x和y)來顯示它。當您顯示視圖時,只需使用這些值設置視圖的佈局參數即可。

0

版本4.0.0增加了一個onTap() listener,它複製了上面的onTouch方法,它不能解決Toast定位問題,但可以爲您節省幾行代碼。