2013-09-21 165 views
0

我終於能夠啓動並運行android GraphView。但是,當我嘗試滾動或縮放沒有發生。我試過使用ScrollView,LinearLayout和其他主機。我目前正在將圖加載到DialogFragment中。android graphview觸摸事件

package com.example.resistograph; 

import android.app.DialogFragment; 
import android.graphics.Color; 
import android.os.Bundle; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.LinearLayout; 

import com.jjoe64.graphview.GraphView; 
import com.jjoe64.graphview.GraphView.GraphViewData; 
import com.jjoe64.graphview.GraphViewSeries; 
import com.jjoe64.graphview.LineGraphView; 

public class GraphFragment extends DialogFragment { 
static String data; 
int[] conversion; 

public GraphFragment() { 

} 

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
     Bundle savedInstanceState) { 
    // TODO Auto-generated method stub 

    String[] lines = data.split("\r\n|\r|\n"); 
    conversion = new int[lines.length]; 

    for(int i=1; i<lines.length; i=i+1){ 
     conversion[i]=Integer.parseInt(lines[i]); 
    } 

    View v = inflater.inflate(R.layout.graph_fragment, container, false); 

    GraphViewSeries exampleSeries = null; 

    for (int x=0; x<lines.length; x=x+1) { 
     exampleSeries = new GraphViewSeries(new GraphViewData[] { 
       new GraphViewData(x, conversion[x]), 
     }); 
    } 

    GraphView graphView = new LineGraphView(
       getActivity() // context 
       , "GraphViewDemo" // heading 
     ); 
    graphView.addSeries(exampleSeries); // data 
    graphView.setScalable(true); 
    graphView.setScrollable(true); 
    graphView.getGraphViewStyle().setHorizontalLabelsColor(Color.BLUE); 
    graphView.getGraphViewStyle().setVerticalLabelsColor(Color.BLUE); 
    LinearLayout layout = (LinearLayout)v.findViewById(R.id.graph); 

    layout.addView(graphView); 
    return v; 
} 
} 

我的佈局文件看起來像這樣。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/graph" 
android:orientation="horizontal" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" > 

</LinearLayout> 

當我去滾動或放大Eclipse日誌這樣說:

09-20 23:45:36.380: D/GraphView(12160): on touch event scale not handled+0.0 
09-20 23:45:36.440: D/GraphView(12160): on touch event scale not handled+0.0 
09-20 23:45:36.460: D/GraphView(12160): on touch event scale not handled+615.3957 
09-20 23:45:36.470: D/GraphView(12160): on touch event scale not handled+613.4519 
09-20 23:45:36.480: D/GraphView(12160): on touch event scale not handled+608.0 
09-20 23:45:36.510: D/GraphView(12160): on touch event scale not handled+0.0 
09-20 23:45:36.540: D/GraphView(12160): on touch event scale not handled+601.4615 
09-20 23:45:36.580: D/GraphView(12160): on touch event scale not handled+598.99097 
09-20 23:45:36.600: D/GraphView(12160): on touch event scale not handled+593.62683 
09-20 23:45:37.770: D/GraphView(12160): on touch event scale not handled+0.0 
09-20 23:45:37.770: D/GraphView(12160): on touch event scale not handled+508.0 
+0

做的graphview例子爲你工作? – appsthatmatter

回答

1

我認爲你需要把graphView.setViewPort(value1, value2);