java - Androidplot - 在绘图区域内定位范围标签

标签 java android androidplot

我正在尝试在图表上设置范围标签的格式,以便它们位于绘图区域内以最大化我的空间。

我遇到的问题是我不知道如何垂直定位范围标签,从而使标签被剪切: image 为了获得图表,我使用以下命令:

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 更改相应地更新标签。

以下是用户平移缩放时更新 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;
    }
});

关于java - Androidplot - 在绘图区域内定位范围标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57720794/

相关文章:

android - 单击刷新按钮刷新 Activity 内容

AndroidPlot - 显示垂直域标签

java - MyBatis 调用带有返回值和 out 参数的存储函数

java - 用swing绘制图形的好方法是什么?

java - 每次调用方法时如何创建一个新文件?

java - 高效的字符串文本搜索

java - Android自定义属性返回null

android - 将图像加载到 SQLite DB 的 SQL 命令

java - AndroidPlot:检测点上的触摸事件

java - Androidplot:具有特定扫描速率的动态绘图