androidplot background image shift

邮差的信 提交于 2019-12-10 20:06:40

问题


I'm trying to separate the background of the graph grid in 3 areas using this code:

int[] data = {0xff000000, 0x80008000, 0xff000000};
bgBitmap = Bitmap.createBitmap(data, 1, 3, Bitmap.Config.ARGB_8888);
RectF rect = plot.getGraphWidget().getGridRect();
BitmapShader myShader = new BitmapShader(
                    Bitmap.createScaledBitmap(bgBitmap, 1, (int) rect.height(), false),
                    Shader.TileMode.REPEAT,
                    Shader.TileMode.REPEAT);
plot.getGraphWidget().getGridBackgroundPaint().setShader(myShader);

So scaling a 3 pixel bitmap to the graph height and repeating it over the whole domain area. However the resulting graph show that the background seems to be shifted up a bit. It looks like the shift size is about equal to the domain label height.

How can I fix this?

Hm cannot post picture because of 'reputation' sigh. Link to the example graph: http://marcel.mesa.nl/androidplot.png


回答1:


I think you're running into the issue mentioned near the end of this thread. Essentially, the origin of the shader is the top-left corner of the screen, not the top-left corner of component for which the background is being drawn using the shader. The solution is to translate to the top-left point of the graphWidget like this:

RectF rect = plot.getGraphWidget().getGridRect();
Matrix m = new Matrix();
m.setTranslate(rect.left, rect.top);
shader.setLocalMatrix(m); // where shader is your shader instance


来源:https://stackoverflow.com/questions/24738800/androidplot-background-image-shift

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!