1

Goal: Multiple Charts in a Scrollview (First just vertical scrollable, but preferred in a Gridview with 2 columns)

Problem: Vertical Scrolling is not working

Hint: The sizing of charts (with onMeasure) and fillViewport = true works

Tried much solutions from stackoverflow (with wrap_content, match_parent, weights etc...), nothing has succeeded.

Changes in MPAndroidChart

mChart.setRotationEnabled(false);
mChart.setTouchEnabled(false);
Disabled OnChartValueSelectedListener, SeekBar.OnSeekBarChangeListener

Layout File

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:elevation="@dimen/elevation"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ScrollView
        android:fillViewport="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingLeft="@dimen/activity_horizontal_margin"
            android:paddingRight="@dimen/activity_horizontal_margin"
            android:paddingTop="@dimen/activity_vertical_margin"
            android:paddingBottom="@dimen/activity_vertical_margin"
            android:orientation="vertical"
            android:weightSum="100"
            tools:context=".MainActivity">

            <LinearLayout android:id="@+id/linearlayout"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="75"
                android:orientation="vertical">
                <MPAndroidChart.PieChartSquare
                    android:id="@+id/chart1"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />
            </LinearLayout>

            <LinearLayout android:id="@+id/linearlayout2"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="75"
                android:orientation="vertical">
                <MPAndroidChart.PieChartSquare
                    android:id="@+id/chart2"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />
            </LinearLayout>

        </LinearLayout>
    </ScrollView>

<android.support.v7.widget.RecyclerView
android:id="@+id/RecyclerView"
android:layout_width="320dp"
android:layout_height="match_parent"
android:layout_gravity="left"

android:background="#ffffff"
android:scrollbars="vertical">

</android.support.v7.widget.RecyclerView>

</android.support.v4.widget.DrawerLayout>

MPAndroidChart.PieChartSquare extends from original PieChart, but I added following Code to size the chars.

   @Override
   protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

    super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    int w = MeasureSpec.getSize(widthMeasureSpec);
    int h = MeasureSpec.getSize(heightMeasureSpec);

    w = Math.min(w, h);
    h = w;

    setMeasuredDimension(w, h);
}

Thanks, and regards

UPDATE

I did the trick with a custom Gridview and then inflating a chartitem.xml for each chart. Unfortenately the PieChartSquare doesn't work (nothing visible), so I have to use the PieChart.

So I don't get a correct sizing of the chart. It is always very very small.

Malte
  • 51
  • 1
  • 10
  • check out this question, it may help. http://stackoverflow.com/questions/37338053/scrollview-overflowing-its-framelayout-parent?noredirect=1#comment62193739_37338053 – Aradhna May 20 '16 at 05:25
  • Hi, the onMeasure method of this post makes the sizing bad, and scrolling isnt affected through that. – Malte May 20 '16 at 06:17

0 Answers0