Search code examples
androidandroid-layoutandroid-scrollviewmpandroidchart

MPAndroidChart Line chart scrollview overlap


I am facing a problem when adding a scrollview to my layout. When ever I change the orientation to landscape and scroll, the views seem to overlap Portrait viewLandscape view

Following below is the code from the layout file. Can any one help me to figure out why the Details and the chart over lap???

<?xml version="1.0" encoding="utf-8"?>

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

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin">

        <com.github.mikephil.charting.charts.LineChart
            android:id="@+id/line_chart"
            android:layout_width="match_parent"
            android:layout_height="300dp"></com.github.mikephil.charting.charts.LineChart>


        <android.support.v7.widget.GridLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:columnCount="2">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/symbol"
                android:text="@string/detail_symbol"
                app:layout_columnWeight="1"
                app:layout_rowWeight="1" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/symbolValue"
                app:layout_columnWeight="1"
                app:layout_rowWeight="1"
                tools:text="IBM" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/price"
                android:text="@string/price"
                app:layout_columnWeight="1"
                app:layout_rowWeight="1" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/priceValue"
                app:layout_columnWeight="1"
                app:layout_rowWeight="1"
                tools:text="Price" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/percentage_change"
                android:text="@string/percentage_change"
                app:layout_columnWeight="1"
                app:layout_rowWeight="1"
                tools:text="Percentage change" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/percentageChangeValue"
                app:layout_columnWeight="1"
                app:layout_rowWeight="1"
                tools:text=".09%" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/absolute_change"
                android:text="@string/absolute_change"
                app:layout_columnWeight="1"
                app:layout_rowWeight="1" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/absolutechangeValue"
                app:layout_columnWeight="1"
                app:layout_rowWeight="1"
                tools:text="5.5" />

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

    </LinearLayout>
</ScrollView>

Solution

  • No need to use external scroll views

    Comment 'computeScroll()' method or 'Utils.postInvalidateOnAnimation(mChart);' in the bellow path. This method may block your thread for 2, 3 minutes and this leads to delay, lagging, live value update issues , etc..

    com/github/mikephil/charting/listener/BarLineChartTouchListener.java

    Definitely this will resolve all scrolling issues like delay, hangs etc...