首页 > 解决方案 > MarkerView 正在切断图形右侧的值

问题描述

使用 Markerview 在图表上显示触摸时的值。但是当它在图表的右侧被触摸时,它会超出屏幕。当它在左侧被触摸时,它不会超出,但它的箭头没有指向图表上的正确值。我正在使用 mpchart Android 库。

这是我的自定义 Markerview 类 xymarkerview.java

public class XYMarkerView extends MarkerView {

private TextView tvContent;
private IAxisValueFormatter xAxisValueFormatter;

private DecimalFormat format;

public XYMarkerView(Context context, IAxisValueFormatter xAxisValueFormatter) 
{
    super(context, R.layout.custom_marker_view);

    this.xAxisValueFormatter = xAxisValueFormatter;
    tvContent = findViewById(R.id.tvContent);
    format = new DecimalFormat("###.0");
}

// callbacks everytime the MarkerView is redrawn, can be used to update the
// content (user-interface)
@Override
public void refreshContent(Entry e, Highlight highlight) {


    tvContent.setText(format.format(e.getY()));

    super.refreshContent(e, highlight);
}


@Override
public MPPointF getOffset() {
    return new MPPointF(-(getWidth() / 2), -getHeight());
}



}

这是我的 customXYmarker.xml

<TextView
    android:id="@+id/tvContent"
    android:layout_width="70dp"
    android:layout_height="40dp"
    android:background="@drawable/bg_rectangle"
    android:padding="8dp"
    android:textStyle="bold"
    android:textColor="#ffffff"
    android:text=""
    />


<ImageView
    android:id="@+id/image_arrow"
    android:layout_marginTop="-1.5dp"
    android:layout_width="16dp"
    android:layout_height="16dp"
    android:layout_marginLeft="27dp"
    android:background="@drawable/icon_arrow_down"
    />

左侧标记问题: 在此处输入图像描述

右侧标记问题 在此处输入图像描述

它在中心值上运行良好,但在最左侧或最右侧的值上无法正常运行。

标签: javaandroidlinechart

解决方案


推荐阅读