Achartengine:在正常图表顶部重绘图表

时间:2012-03-09 15:52:49

标签: android achartengine

在我的应用中,我切换了两个不同图表的视图。第一次是绘制的图形看起来很完美,但是当我转到另一个并且回来时看起来它绘制了两次相同的图形,但是大小不同,一旦你点击图形它就会改变并且看起来很完美。

看起来有线的屏幕是:

The screen when it looks wired is:

绘制图形的代码始终相同。这个功能是:

private void downloadInfo(String app, String object) {
    // Display flow graph
    //
    String query = "Select name from relation where obj_app = '" + app
            + "' and obj_name = '" + object
            + "' and obj_type = 1 and type= 22";
    String data = "name";
    String comparateur = new DataBaseAccess().execute(query, data);
    String compAux[] = comparateur.split("&");
    query = "Select * from data_1h where app = '" + app
            + "' and obj_name = '" + compAux[0] + "' and obj_type= 22";
    String file = new DataBaseAccess().execute(query, "file-date");
    String[] fileAux = file.split("&");
    date = fileAux[1];
    GraphicalView mChartView = new DebitGraph().execute(ShowGraph.this,
            fileAux[0], fileAux[1], compAux[0], object);
    RelativeLayout layout = (RelativeLayout) findViewById(R.id.graph1);
    layout.removeAllViews();
    Display display = getWindowManager().getDefaultDisplay();
    RelativeLayout.LayoutParams paramsForChart1 = new RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT);
//  paramsForChart1.bottomMargin = 25;
    layout.addView(mChartView, paramsForChart1);
    // Display Meteo graph
    query = "Select name from relation where obj_app = '" + app
            + "' and obj_name = '" + object
            + "' and obj_type = 1 and type= 20";
    data = "name";
    String station = new DataBaseAccess().execute(query, data);
    String stationAux[] = station.split("&");
    query = "Select * from data_1h where app = '" + app
            + "' and obj_name = '" + stationAux[0] + "' and obj_type= 20";
    data = "file-date";
    file = new DataBaseAccess().execute(query, data);
    fileAux = file.split("&");
    GraphicalView mChartView2 = new Meteo().execute(ShowGraph.this,
            fileAux[0], fileAux[1], stationAux[0], prec, temp);
    RelativeLayout.LayoutParams paramsForChart2 = new RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT);
    layout = (RelativeLayout) findViewById(R.id.graph2);
    layout.removeAllViews();
//  paramsForChart2.bottomMargin = 25;
    layout.addView(mChartView2, paramsForChart2);

    // Display check boxes for temperature and precipitation
    RelativeLayout check = (RelativeLayout) findViewById(R.id.checks);
    check = (RelativeLayout) findViewById(R.id.checks);
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    LinearLayout checkbox = (LinearLayout) inflater.inflate(
            R.layout.checkboxes, null);
    check.addView(checkbox);

    // Update text bar text with meteo info
    /*
     * TextView meteo = (TextView) findViewById(R.id.meteo);
     * meteo.setText("Méteo " + stationAux[0] + " " + fileAux[1]);
     * meteo.setTextColor(Color.BLACK); meteo.setTextSize(14);
     */
    if (MyDialog.isShowing()) {
        MyDialog.dismiss();
    }
}

我已经更改了achartengine库以更改缩放按钮,但没有别的!

在我的logCat中,每当屏幕发生疯狂时我都会收到此警告:

03-13 12:01:16.767: W/InputManagerService(229): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@2b1fb958

我一直在论坛中看到这个错误,但我找到的任何答案都很有用!

有关详细信息,看起来我遇到与此帖相同的问题:

Achartengine: graph redraw on top of normal graph

但是当我评论我的onResume()时,问题不会消失!

有什么想法吗? 谢谢!

1 个答案:

答案 0 :(得分:2)

当您返回到图表视图时,您可能需要在其上调用repaint()。

避免此类屏幕瑕疵的另一种方法是调用renderer.setInScroll(true);