android - AndroidPlot 获取直线的 Y 位置
问题描述
我想TextLabelWidget
在 android Plot 中的特定行上方放置一个。
有没有办法将它直接连接到一条线或计算一条线的确切 Y 位置。
https://stackoverflow.com/posts/comments/87452134?noredirect=1
到目前为止,这是我的代码:
TextLabelWidget txtText = new TextLabelWidget(
rdPuls.getLayoutManager(),
"Some Text",
null, // TextLabelWidget instances "pack" to wrap the actual text size
TextOrientation.HORIZONTAL);
txtText.getLabelPaint().setColor(getColor(R.color.biosign_green));
txtText.getLabelPaint().setTextSize(PixelUtils.dpToPix(15));
txtText.position(
// add a right margin of 4dp:
0, PixelUtils.dpToPix(80)
// center the text with the plot space vertically:
PixelUtils.dpToPix(80), VerticalPositioning.ABSOLUTE_FROM_BOTTOM,
// use the middle of the right edge of the text widget as the anchor:
Anchor.RIGHT_MIDDLE);
图片:
解决方案
如果您只想用一些文本显示一条直线,您可以使用以下子类之一XYValueMarker
:
YValueMarker marker = new YValueMarker(35, "someText");
plot.addMarker(marker);
// later, if you want to dynamically move it around: (dont forget
// to call plot.redraw() if you do though)
marker.setValue(34);
您可以使用替代构造函数或marker.setTextPosition(...)
精确控制文本出现的位置。
推荐阅读
- angular - @ngrx EntityAdapter 时如何停止按 id 排序
- c# - “XDG0062 灾难性故障..”。尝试在 .Net Core WPF 应用程序中使用 UWP 控件时。为什么?
- java - 为什么java注解可以包含一个字段甚至一个类?
- typescript - 你能在不捆绑特定路径模块的情况下让 webpack 解析 tsconfig 路径吗?
- c# - Xamarin:选择器标题不会以编程方式更改
- css - 在带有 freemarker 和 gradle 的 Spring Boot 中使用 SCSS
- java - 试图在当前类的构造函数中创建另一个类的对象
- linux - 根据年份将文件复制到文件夹中
- node.js - 下载/运行另一个人的 React App
- c# - 这种并发问题可以用 async/await 解决吗?