(this question is also valid for ScrollView)
I need to place a LineChart inside HorizontalScrollView. I do not wish to scroll inside the chart (meaning the chart renders the scroll itself and after multiple tesst, it's quite laggy) unless it is the last solution.
The library is MPAndroidChart.
Based on this post on Telerik it should not be complicated.
Unfortunately I cannot seem to achieve the aimed result.
This is my XML code :
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.github.mikephil.charting.charts.LineChart
android:layout_width="2000dp"
android:layout_height="match_parent"
android:fillViewport="true"
android:id="@+id/chart"/>
</HorizontalScrollView>
Nothing really fancy.
Android Studio internal designer shows a really shrinked chart and my phone does too.
What is wrong ?
Thanks for the help!
Use a LinearLayout as a container for your Line chart:
<HorizontalScrollView
android:id="@+id/hsvChart"
android:layout_width="800dp"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.github.mikephil.charting.charts.LineChart
android:id="@+id/chart"
android:layout_width="600dp"
android:layout_height="match_parent"
android:layout_marginBottom="3dp"
android:layout_marginTop="3dp" />
</LinearLayout>
</HorizontalScrollView>
This will prevent your chart from shrinking
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With