9
votes

I want to show a PieChart in my fragment. Following is the xml I have written,

<ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/background">

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

            <com.github.mikephil.charting.charts.PieChart
                android:id="@+id/piechart"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />

        </LinearLayout>
   </ScrollView>

The problem is, PieChart is not working if I give match_parent or wrap_content. If i give fixed height and width it works fine. Also, if I remove the ScrollView , it works like a charm! So what needs to be done in case of ScrollView?

1
Add a fixed height for the piechart - Philipp Jahoda
@PhilippJahoda: Have you read the whole question? - Shruti Dasgopal
Yes, and that is my suggestion. - Philipp Jahoda
I suppose it is a custom class you haven't written yourself; when you write a custom class you have to deal with all the different constructors that "initialize" an object. It MIGHT be that match_parent doesn't trigger any. Can you put a print in the constructor and check if it gets executed when being placed in the view? - user2875404
@PhilippJahoda kindly specify the height? - Moeez

1 Answers

-2
votes

Add below attribute in scroll view

android:fillViewport="true"

Refer here