1. Daniel Nadeau
  2. HoloGraphLibrary
Issue #50 new

Line Graph View gets chopped off on rotation.

Sudhir Khanger
created an issue

The graph only works in whichever mode you open the app. If you open the app in portrait mode and draw a line graph it will get chopped off if you rotate the device. The other way around is also true.

The code is pretty simple at the moment. If you could point me in any direction that would be great. Let me know if you need more information.

May 27, 2014 30419 PM GMT+0530.png

May 27, 2014 30643 PM GMT+0530.png

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <Button 
        android:id="@+id/clear_button"
        android:layout_width="wrap_content"
        android:layout_height="48dp"
        android:text="@string/clear_string"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true" />

    <Button 
        android:id="@+id/graph_button"
        android:layout_width="wrap_content"
        android:layout_height="48dp"
        android:text="@string/graph_string"
        android:layout_toLeftOf="@id/clear_button"
        android:layout_alignParentTop="true" />

    <EditText 
        android:id="@+id/name_edittext"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/enter_a_name_string"
        android:layout_toLeftOf="@id/graph_button"
        android:layout_alignBottom="@id/graph_button"
        android:inputType="text"
        android:maxLines="1"
        android:maxLength="20" />

    <com.google.android.gms.ads.AdView 
        xmlns:ads="http://schemas.android.com/apk/res-auto"
        android:id="@+id/adView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        ads:adSize="SMART_BANNER"
        ads:adUnitId="xxxxxxxxxxxxxxxxxxxxxx"
        android:layout_alignParentBottom="true"/>

    <com.echo.holographlibrary.LineGraph
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/name_edittext"
        android:layout_above="@id/adView"
        android:id="@+id/graph_view"
        android:layout_margin="5dp" />

</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.appname"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="19" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <meta-data  android:name="com.google.android.gms.version"
                    android:value="@integer/google_play_services_version"/>
        <activity
            android:name="com.example.appname.MainActivity"
            android:label="@string/app_name"
            android:configChanges="orientation|screenSize" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="com.google.android.gms.ads.AdActivity"
             android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
    </application>
  <uses-permission android:name="android.permission.INTERNET"/>
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
</manifest>

Comments (6)

  1. Scott Baar

    Remove orientation from android:configChanges="orientation|screenSize" > and the problem will be fixed.

    I thought that you would be able to fix the problem by calling forcelayout, invalidate or requestlayout on the relative layout or the linegraph view but in either onResume or onConfiguration changed, but none of that works.

    So the exact problem is that even though canvas is getting the correct dimensions for the view, only part of the canvas is displaying.

  2. Daniel Nadeau repo owner

    My guess is that you need to force mFullImage to be null on rotation. This way, the old bitmap which is cached isn't used to redraw the canvas. I don't have my computer with me, but Scott if you'd like to try that, thatd be awesome :)

  3. Daniel Nadeau repo owner

    It does... Its just drawing an old image. The issue is that I implemented the mFullImage as a way to cache the graph. It stays that size when its rotated because it was never told anything changed. Setting it to null on rotation seems to make the most sense. I think this is an issue in all of the graphs.

  4. Log in to comment