java - Androidplot - 在绘图区域内定位范围标签
问题描述
我正在尝试在我的图表上格式化范围标签,以便它们位于绘图区域内以最大化我的房地产。
我遇到的问题是我无法弄清楚如何垂直放置范围标签,让我的标签被剪掉: 为了得到图示,我使用以下内容:
plot.setRangeBoundaries(-300, 300, BoundaryMode.FIXED);
plot.getGraph().setMargins(-100,0,0,-80);
plot.getGraph().getLineLabelInsets().setLeft(PixelUtils.dpToPix(60));
在内部定位标签的最佳方式是什么?
解决方案
所以我永远无法让标签正确格式化,作为一种解决方法,我添加了自己的自定义标签。
有一种方法可以通过 LineLabelStyle 设置自定义标签,但如果我们要使用它,我们最终会遇到同样的情况。
因此,我们使用带有 xml 属性 android:elevation="1dp" 的 TextView。因为我实现了 PanZoom,我们必须拦截触摸事件并根据 PanZoom 更改相应地更新标签。
这是用户 PanZooms 时更新 TextView 标签的基本实现:
PanZoom.attach(plot).setDelegate(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
switch (motionEvent.getAction()) {
case MotionEvent.ACTION_DOWN: {
//Update graph labels with plot.getBounds().asRectF();
rangeLabel1.setText("My TextView rangeLabel gets updated here!");
rangeLabel2.setText("You have to calculate value for each label")
domainLabel1.setText("Do the same for domain labels also");
domainLabel2.setText("etc...");
break;
}
case MotionEvent.ACTION_MOVE: {
//Update graph labels with plot.getBounds().asRectF();
rangeLabel1.setText("My TextView rangeLabel gets updated here!");
rangeLabel2.setText("You have to calculate value for each label")
domainLabel1.setText("Do the same for domain labels also");
domainLabel2.setText("etc...");
break;
}
case MotionEvent.ACTION_UP: {
//Update graph labels with plot.getBounds().asRectF();
rangeLabel1.setText("My TextView rangeLabel gets updated here!");
rangeLabel2.setText("You have to calculate value for each label")
domainLabel1.setText("Do the same for domain labels also");
domainLabel2.setText("etc...");
break;
}
}
//Return false to allow PanZoom to receive control
return false;
}
});
推荐阅读
- r - 匹配日期范围从R中的不同数据框
- php - 尝试在子域之间共享会话时出现 ERR_TOO_MANY_REDIRECTS
- intellij-plugin - Intellij 中的 Spring 状态机建模工具支持
- cookies - 使用 JMeter 在 cookie 管理器中设置 JSession id
- excel - 写入 txt 文件时,如果已经有同名文件,VBA 中是否有办法在文件名中添加版本号?
- google-chrome - 当 declarativeNetRequest 阻止请求时触发操作
- html - 尝试向 Wordpress archives.php 文件添加自定义菜单
- python - 如何在 django 中调试这个 stracktrace?
- oracle - 我在使用( rowid )删除 PL/SQl 中的重复行时遇到问题
- javascript - 使用 URL + GET 参数填写表单按钮而不提交表单