1

我在 android 中学习 Pie AChartEngine,我想尝试在 ScrollView 中添加一些 pie。但这没有滚动...如何解决?

这是我的 xml

 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
android:layout_height="fill_parent"
        android:fillViewport="true" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:id="@+id/general" >

            <TextView
                android:id="@+id/tv_title"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal"
                android:text="@string/str_tv_title" />

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

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Large Text"
                android:textAppearance="?android:attr/textAppearanceLarge" />

            <TextView
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Medium Text"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <TextView
                android:id="@+id/textView3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="TextView" />




        </LinearLayout>
    </ScrollView>

这个java

 private void openChart(){      

    // Pie Chart Slice Names
    code = new String[] {
            "Eclair & Older", "Froyo", "Gingerbread", "Honeycomb",
            "IceCream Sandwich", "Jelly Bean" 
    };      

    // Pie Chart Slice Values
    double[] distribution = { 3.9, 12.9, 55.8, 1.9, 23.7, 1.8 } ;

    // Color of each Pie Chart Slices
    int[] colors = { Color.BLUE, Color.MAGENTA, Color.GREEN, Color.CYAN, Color.RED,
                     Color.YELLOW };

    DisplayMetrics metrics = getBaseContext().getResources().getDisplayMetrics();
    float val = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 18, metrics);

    // Instantiating CategorySeries to plot Pie Chart       
    CategorySeries distributionSeries = new CategorySeries(" Android version distribution as on October 1, 2012");
    for(int i=0 ;i < distribution.length;i++){
        // Adding a slice with its values and name to the Pie Chart
        distributionSeries.add(code[i], distribution[i]);
    }   

    // Instantiating a renderer for the Pie Chart
    DefaultRenderer defaultRenderer  = new DefaultRenderer();       
    for(int i = 0 ;i<distribution.length;i++){ 

        // Instantiating a render for the slice
        SimpleSeriesRenderer seriesRenderer = new SimpleSeriesRenderer();       
        seriesRenderer.setColor(colors[i]);
        seriesRenderer.setDisplayChartValues(true);

        // Adding the renderer of a slice to the renderer of the pie chart
        defaultRenderer.addSeriesRenderer(seriesRenderer);
    }

    defaultRenderer.setChartTitle("Android version distribution as on October 1, 2012 ");
    defaultRenderer.setChartTitleTextSize(20);
    defaultRenderer.setZoomButtonsVisible(true); 
    defaultRenderer.setLabelsTextSize(val);

    // Getting a reference to view group linear layout chart_container
    LinearLayout chartContainer = (LinearLayout) findViewById(R.id.chart_container);


    // Getting PieChartView to add to the custom layout
    mChart = ChartFactory.getPieChartView(getBaseContext(), distributionSeries, defaultRenderer);

    defaultRenderer.setClickEnabled(true);
    defaultRenderer.setZoomEnabled(true);
    defaultRenderer.setSelectableBuffer(10);
    defaultRenderer.setApplyBackgroundColor(true);
    defaultRenderer.setBackgroundColor(Color.argb(100, 50, 50, 50));
    defaultRenderer.setChartTitleTextSize(20);
    defaultRenderer.setLabelsTextSize(20);
    defaultRenderer.setLegendTextSize(20);
    defaultRenderer.setZoomButtonsVisible(false);
    defaultRenderer.setInScroll(true);
    defaultRenderer.setStartAngle(90);
    defaultRenderer.setPanEnabled(true);

    mChart.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            SeriesSelection seriesSelection = mChart.getCurrentSeriesAndPoint();
            if (seriesSelection != null) {

                // Getting the name of the clicked slice
                int seriesIndex = seriesSelection.getPointIndex();
                String selectedSeries="";
                selectedSeries = code[seriesIndex];                 

                // Getting the value of the clicked slice
                double value = seriesSelection.getXValue();
                DecimalFormat dFormat = new DecimalFormat("#.#");

                // Displaying the message
                Toast.makeText(
                        getBaseContext(),
                        selectedSeries + " : "  + Double.valueOf(dFormat.format(value)) + " % " ,
                        Toast.LENGTH_SHORT).show();
            }
    }
    });

    // Adding the pie chart to the custom layout
    chartContainer.addView(mChart);
}

我在 ScrollView中添加了android:fillViewport="true"并且添加了defaultRenderer.setInScroll(true); 在java中也是如此,但它不起作用......

我希望任何人都可以帮助我。对不起,如果我的英语不好...

4

2 回答 2

0
 <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:id="@+id/general" >

尝试将android:layout_height此处设置为wrap_content

于 2013-10-10T00:47:00.737 回答
0

mRenderer.setZoomEnabled(false);

mRenderer.setPanEnabled(false);

mRenderer.setZoomRate(6.0f);

mRenderer.setShowLabels(true);

mRenderer.setFitLegend(true);

mRenderer.setInScroll(true);

这对我有用。

于 2014-03-06T11:40:11.323 回答