首页 > 解决方案 > Androidplot - 在绘图区域内定位范围标签

问题描述

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

我遇到的问题是我无法弄清楚如何垂直放置范围标签,让我的标签被剪掉: 图片 为了得到图示,我使用以下内容:

plot.setRangeBoundaries(-300, 300, BoundaryMode.FIXED);
plot.getGraph().setMargins(-100,0,0,-80);
plot.getGraph().getLineLabelInsets().setLeft(PixelUtils.dpToPix(60));

在内部定位标签的最佳方式是什么?

标签: javaandroidandroidplot

解决方案


所以我永远无法让标签正确格式化,作为一种解决方法,我添加了自己的自定义标签。

有一种方法可以通过 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;
    }
});


推荐阅读