I am trying to draw a graph in Android. I want the graph to scale to current screen size, so instead of setting them explicitly in the constants, I get the size of an LinearLayout
which is intended to contain the graph. However, there is a problem that it's not possible to get sizes in activity's onCreate()
, so I use a custom LinearLayout with overridden onSizeChanged()
. I include it into layout with:
view class="com.nnevod.loggraph.graph$GraphDisplayLayout"
android:layout_height="fill_parent"
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_weight="1"
android:background="@color/White"
I've omitted angular brackets.
In the overridden onSizeChanged()
, dimensions of the view are read, then everything is done as described in many graphing examples: a Bitmap is created, passed to a graph-drawing class, an ImageView is created, is set with the Bitmap, and then added to the custom LinearLayout.
Problem is, the graph's image is not visible. However, if I try to inspect it with HierarchyViewer
, the image becomes visible. If I cut-paste the code from onSizeChanged()
to activity's onCreate()
, sans using preset dimensions instead of measured ones, everything is displayed nicely.
So, my question is what I'm doing wrong? I've had assumptions that either I'm using a wrong context in custom onSizeChanged()
, or it is not possible to update the view from there, and I should somehow pass the measured dimensions to the activity and do the attachment of the Bitmap in some of activity's methods.
Though on the context part, I've tried using all available contexts, including using activity's context, to no avail.
If needed, I'll provide more code.