Вопрос

I'm looking for a way to apply a Style to an AndroidPlot element, and the documentation is precious scarce. Basically, I want to externalize the graph design elements into my styles.xml file, but I'm not sure how to do this. I've tried adding an element to Attrs.xml but to no avail.

My activity_main.xml layout file:

<com.androidplot.xy.XYPlot
        android:id="@+id/main_xyplot_main"
        style="@style/GraphStyle"

        androidPlot.domainLabel="@string/graph_x_axis"
        androidPlot.titleWidget.labelPaint.textSize="@dimen/title_font_size"
        androidPlot.domainLabelWidget.labelPaint.textSize="@dimen/domain_label_font_size"
        androidPlot.rangeLabelWidget.labelPaint.textSize="@dimen/range_label_font_size"
        androidPlot.rangeLabel="@string/graph_y_axis"
        androidPlot.title="@string/graph_title"
        androidPlot.renderMode="use_background_thread"

        androidPlot.graphWidget.rangeLabelPaint.textSize="@dimen/range_tick_label_font_size"
        androidPlot.graphWidget.rangeOriginLabelPaint.textSize="@dimen/range_tick_label_font_size"
        androidPlot.graphWidget.domainLabelPaint.textSize="@dimen/domain_tick_label_font_size"
        androidPlot.graphWidget.domainOriginLabelPaint.textSize="@dimen/domain_tick_label_font_size"

        androidPlot.graphWidget.gridLinePaint.color="#000000"
        androidPlot.graphWidget.marginBottom="25dp"
        androidPlot.graphWidget.marginLeft="20dp"
        androidPlot.graphWidget.marginRight="10dp"
        androidPlot.graphWidget.marginTop="20dp"

        androidPlot.legendWidget.heightMetric.value="25dp"
        androidPlot.legendWidget.iconSizeMetrics.heightMetric.value="15dp"
        androidPlot.legendWidget.iconSizeMetrics.widthMetric.value="15dp"
        androidPlot.legendWidget.positionMetrics.anchor="right_bottom"
        androidPlot.legendWidget.textPaint.textSize="10dp"

        android:layout_above="@id/main_percentage"
        android:gravity="top"

        android:visibility="invisible" />

Styles.xml

 <style name="GraphStyle">

    <item name="android:paddingBottom">0dp</item>
    <item name="android:paddingLeft">0dp</item>
    <item name="android:paddingRight">0dp</item>
    <item name="android:paddingTop">0dp</item>
    <item name="android:layout_width">"wrap_content"</item>
    <item name="android:layout_height">"wrap_content"</item>

</style>

Is there even a way to do this? I want to put all of those androidPlot.* into the GraphStyle.

Thanks!

Это было полезно?

Решение

Unfortunately this is not currently possible. Androidplot is packaged as a Jar and (as far as I am aware) it is not possible to include the styleable definitions that are used by in a jar. This means that you won't be able to override the Androidplot specific fields of the Plot (those that begin with "androidPlot") but can still override the fields that come from the View base class (those that begin with "android").

Going forward, we are considering using .aar instead of .jar as the packaging format. Among other things, this should let us include styleable definitions in the artifact, getting rid of the above limitation. Here's a link to the thread on that topic.

UPDATE: As of 0.6.2 (the current development version) Androidplot is available as a .aar with limited styleable support, however as 0.6.2 matures more and more attributes are being added. See this thread for details.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top