我尝试使用以下代码将图形网格的背景分为 3 个区域:
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);
因此,将 3 像素位图缩放到图形高度,并在整个域区域上重复它。
然而,生成的图表显示背景似乎向上移动了一点。
看起来移位大小大约等于域标签高度。
我怎样才能解决这个问题?
嗯,由于“声誉”叹息,无法发布图片。
链接到示例图:http://marcel.mesa.nl/androidplot.png http://marcel.mesa.nl/androidplot.png
我认为您遇到了接近尾声时提到的问题这个线程 https://groups.google.com/forum/?fromgroups#!searchin/androidplot/matrix/androidplot/PjkctbzGZlo/0NuN821W7IYJ。本质上,着色器的原点是屏幕的左上角,而不是使用着色器绘制背景的组件的左上角。解决方案是像这样转换到 graphWidget 的左上角:
RectF rect = plot.getGraphWidget().getGridRect();
Matrix m = new Matrix();
m.setTranslate(rect.left, rect.top);
shader.setLocalMatrix(m); // where shader is your shader instance
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)