我正在尝试创建我的CustomMarkerView类。但是当我覆盖 refreshContent 时,它会显示方法不会覆盖其超类,并且“highlight”参数永远不会被使用。
CustomMarkerView.java示例代码
public class CustomMarkerView extends MarkerView {
private TextView tvContent;
public CustomMarkerView (Context context, int layoutResource) {
super(context, layoutResource);
// this markerview only displays a textview
tvContent = (TextView) findViewById(R.id.tvContent);
}
// callbacks everytime the MarkerView is redrawn, can be used to update the
// content (user-interface)
@Override
public void refreshContent(Entry entries, Highlight highlight) {
tvContent.setText("" + entries.getVal());
// set the entry-value as the display text
}
@Override
public int getXOffset() {
// this will center the marker-view horizontally
return -(getWidth() / 2);
}
@Override
public int getYOffset() {
// this will cause the marker-view to be above the selected value
return -getHeight();
}
}
我直接处理了
中的代码
https://github.com/PhilJay/MPAndroidChart/wiki/MarkerView
我缺少什么?
答案 0 :(得分:1)
嘿,刚刚检查了你的代码。如果您将MPAndroidChart
版本更新为
compile 'com.github.PhilJay:MPAndroidChart:v2.2.5'
并使用下面的代码(在您的代码中进行了更改),似乎在我身边正常工作......
public class CustomMarkerView extends MarkerView {
private TextView tvContent;
public CustomMarkerView (Context context, int layoutResource) {
super(context, layoutResource);
// this markerview only displays a textview
tvContent = (TextView) findViewById(R.id.tvContent);
}
// callbacks everytime the MarkerView is redrawn, can be used to update the
// content (user-interface)
@Override
public void refreshContent(Entry entries, Highlight highlight) {
tvContent.setText(" " + entries.getVal());
// set the entry-value as the display text
}
@Override
public int getXOffset(float xpos) {
return -(getWidth()/2);
}
@Override
public int getYOffset(float ypos) {
return -getHeight();
}
}