Я хотел использовать MPAndroidChartLibrary в своем приложении, но у меня возникли проблемы, которые я не могу решить самостоятельно. Я хотел бы поместить диаграмму в CardView, которая хранится внутри ListView. XML-файл CardView выглядит следующим образом:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
card_view:cardCornerRadius="2dp"
card_view:contentPadding="16dp"
card_view:cardUseCompatPadding="true"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textDateStartTitle"
android:paddingLeft="5dp"
android:textSize="26sp"
android:textColor="@color/accent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:gravity="left"/>
<com.github.mikephil.charting.charts.PieChart
android:id="@+id/pie_chart"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
</android.support.v7.widget.CardView>
</FrameLayout>
При открытии фрагмента, содержащего эти CardViews, я получаю сообщение об ошибке:
java.lang.IllegalArgumentException: ширина и высота должны быть > 0 в android.graphics.Bitmap.createBitmap(Bitmap.java:808) в android.graphics.Bitmap.createBitmap(Bitmap.java:787) в android.graphics.Bitmap. createBitmap(Bitmap.java:754) на com.github.mikephil.charting.charts.Chart.onSizeChanged(Chart.java:2197)
Когда я устанавливаю android:layout_width
и android:layout_height
на некоторые фиксированные значения (например, 200dp) внутри com.github.mikephil.charting.charts.PieChart
, диаграмма выглядит нормально, и ошибок нет. Как избавиться от этой ошибки, имея ширину и высоту в зависимости от родителя/контента?