我终于能够启动并运行android GraphView 。但是,当我尝试滚动或缩放时,什么也没有发生。我尝试过使用 ScrollView、LinearLayout 和许多其他工具。我目前正在将图表加载到 DialogFragment 中。
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>
当我滚动或缩放时,日食日志会这样说:
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