java - 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"
/>
它在中心值上运行良好,但在最左侧或最右侧的值上无法正常运行。
解决方案
推荐阅读
- c# - Serilog MSSqlServer 没有记录错误
- r - 使用“点击”功能以编程方式启动 R 闪亮的动作按钮
- python - Python 中的 Microsoft 翻译器用于翻译整个 JSON 文件
- python - 在 conda install 后导入模块时 jupyter notebook 中的 ModuleNotFoundError
- python - 尝试对文件使用多处理但当我让用户输入路径时冻结
- arrays - JSON Path如何获取具体数据?
- angular - 我们如何使用以下代理配置在 IIS 上部署 Angular 项目?
- c++ - 什么时候在编译时评估 constexpr?
- linux - 我如何在 openSUSE 的桌面上创建/保存一些东西
- css - 如何使该 div 居中?(轮播/OWL JS/Boostrap)