achartengine - 添加外部ImageButtons以放大图表旁边的视图会导致奇怪的UI行为

时间:2012-01-26 16:55:19

标签: android charts achartengine

我想在视图顶部的视图上使用Button。

问题:

当我按下按钮时,图表视图的克隆会出现挤压在按下按钮的后面。它只有一秒然后消失。看看打印屏幕......

image link

有没有人知道为什么会这样?

我正在附加虚拟源代码:

layout(main.xml):

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/chart"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" />

    <LinearLayout
        android:id="@+id/layXzoom"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:orientation="horizontal"
        android:padding="5dp" >

        <Button
            android:id="@+id/btnXzoomOut"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Test button" />
    </LinearLayout>

</RelativeLayout>

和活动:

    import java.util.ArrayList;
    import java.util.Date;
    import java.util.List;
    import java.util.Random;

    import org.achartengine.ChartFactory;
    import org.achartengine.GraphicalView;
    import org.achartengine.chart.PointStyle;
    import org.achartengine.chart.TimeChart;
    import org.achartengine.model.TimeSeries;
    import org.achartengine.model.XYMultipleSeriesDataset;
    import org.achartengine.renderer.XYMultipleSeriesRenderer;
    import org.achartengine.renderer.XYSeriesRenderer;

    import android.app.Activity;
    import android.graphics.Color;
    import android.os.Bundle;
    import android.widget.ImageButton;
    import android.widget.LinearLayout;

    public class TestgraphActivity extends Activity {
    /** Called when the activity is first created. */
    private XYMultipleSeriesDataset mDataset;
    private XYMultipleSeriesRenderer mRenderer;
    List<double[]> values = new ArrayList<double[]>();
    private GraphicalView mChartView;
    private TimeSeries time_series;

    // chart container
    private LinearLayout layout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        layout = (LinearLayout) findViewById(R.id.chart);

        // create dataset and renderer
        mDataset = new XYMultipleSeriesDataset();
        mRenderer = new XYMultipleSeriesRenderer();
        mRenderer.setAxisTitleTextSize(16);
        mRenderer.setChartTitleTextSize(20);
        mRenderer.setLabelsTextSize(15);
        mRenderer.setLegendTextSize(15);
        mRenderer.setPointSize(3f);

        XYSeriesRenderer r = new XYSeriesRenderer();
        r.setColor(Color.GREEN);
        r.setPointStyle(PointStyle.CIRCLE);
        r.setFillPoints(true);
        mRenderer.addSeriesRenderer(r);
        mRenderer.setClickEnabled(true);
        mRenderer.setSelectableBuffer(20);
        mRenderer.setPanEnabled(true);

        time_series = new TimeSeries("test");

        mDataset.addSeries(time_series);

        fillData();

        mChartView = ChartFactory.getTimeChartView(this, mDataset, mRenderer,
                "H:mm:ss");

        layout.addView(mChartView);
    }

    private void fillData() {
        long value = new Date().getTime() - 3 * TimeChart.DAY;
        for (int i = 0; i < 100; i++) {
            time_series.add(new Date(value + i * TimeChart.DAY / 4), i);
        }
    }
}

谢谢, 托尼

1 个答案:

答案 0 :(得分:1)

toni也在aChartEngine问题跟踪器上发布了这个问题,并在那里得到了回答(在某种程度上)。

问题的链接:http://code.google.com/p/achartengine/issues/detail?id=171

解决方案摘要:

renderer.setInScroll(true);

似乎照顾了这些文物。