Here is the markerview file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/white">
<TextView
android:id="@+id/tvContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/fit"
android:ellipsize="end"
android:gravity="center"
android:minWidth="@dimen/dp_40"
android:singleLine="true"
android:tag="custommarker"
android:text="10"
android:textColor="@color/black"
android:textSize="15sp" />
</RelativeLayout>
Here is the custommarkerview classs
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 e, Highlight highlight) {
tvContent.setText("" + e.getY()); // set the entry-value as the display text
super.refreshContent(e, highlight);
}
private MPPointF mOffset;
@Override
public MPPointF getOffset() {
if (mOffset == null) {
// center the marker horizontally and vertically
mOffset = new MPPointF(-(getWidth() / 2), -getHeight());
}
return mOffset;
}
}
question from:
https://stackoverflow.com/questions/65916954/mpcharts-android-is-able-to-show-markerview-background-but-not-able-to-update-te 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…