Custom view annotation


#1

I’m trying to use a custom view for an annotation but the layout doesn’t seem to propagate to its children.

Here’s the layout I’m using:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:orientation="horizontal"
        android:gravity="top"
        android:background="#ff0000"
        android:baselineAligned="false"
        >

    <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="#0000ff"
            >
    </LinearLayout>
</LinearLayout>

And here’s the relevant code:

NumberRange zeroToOneRange = new NumberRange(0D, 1D);
        NumberAxis annotationXAxis = new NumberAxis(zeroToOneRange);
        styleXAxis(annotationXAxis);
        NumberAxis annotationYAxis = new NumberAxis(zeroToOneRange);
        chart.addXAxis(annotationXAxis);
        chart.addYAxis(annotationYAxis);

        final ViewGroup testLayout = (ViewGroup) getActivity().getLayoutInflater().inflate(R.layout.test_layout, null, false);
        testLayout.setLayoutParams(new ViewGroup.LayoutParams(0, 0));
        Annotation testAnnotation = chart.getAnnotationsManager().addViewAnnotation(testLayout, 0, 0, annotationXAxis, annotationYAxis);
        testAnnotation.setXRange(zeroToOneRange);
        testAnnotation.setYRange(zeroToOneRange);

This code is towards the end of onCreate of my SupportChartFragment subclass. This is obviously a dumbed-down example to illustrate the problem. I would expect a full blue overlay on top of my chart, but instead I’m getting a red one.

Is there a workaround to allow view containers (ViewGroups) to be used as custom view annotations? I tried doing a requestLayout and a forceLayout on my annotation view inside a data range listener but that didn’t make a difference.

This is using premium 1.4.1. I’ll give it a shot soon using 1.5.

Thanks,

Radu


#2

I tried a few more children for the LinearLayout, and I’m getting some strange results:

This is showing in the top left corner:

<TextView
            android:background="@drawable/gradient_bg"
            android:gravity="center"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:text="TESTING 123"
            />

Adding layout_weight which should make it span the whole width (since the parent linearlayout is orientation horizontal)  makes it disappear:

<TextView
            android:gravity="center"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:text="TESTING 123"
            android:layout_weight="1"
            />

Using wrap content also makes it disappear:

<TextView
            android:gravity="center"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TESTING 123"
            />

So it looks that only having an explicit width and height set (like 40dp in the first example) makes it visible.

Any ideas for workarounds?


#3

Hello Radu,

Thanks for getting in touch and providing such in depth information. 

We are currently looking into this. We will attempt to recreate the problem and we will let you know what our findings are.

Thanks,

Kai.


#4

Hi Radu,

Just to let you know we’ve now released v1.6.0 of ShinobiCharts for Android which includes a fix for this bug. It’s available in the Customer Portal and as a trial download from http://www.shinobicontrols.com/android.

Kind regards,

Patrick