【发布时间】:2018-04-19 05:56:32
【问题描述】:
1.我正在尝试将标记视图设置为条形图。
2.Marker 背景图片显示正确,但 Value 未显示在标记顶部。
3.同时单击每个条 Toast 显示值。但无法设置标记视图的顶部
请帮我解决这个问题,在此先感谢。
gradle 库。
implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3'
barchart_marker_view_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/ic_action_markericon"
android:gravity="center">
<TextView
android:id="@+id/tvContent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:padding="5dp"
android:singleLine="true"
android:text="6565"
android:textColor="@color/color_white"
android:textSize="8sp" />
</RelativeLayout>
Custommarkerview.class
public class CustomMarkerView extends MarkerView implements IMarker{
Context mContext;
private TextView tvContent;
public BarchartCustomMarkerView1(Context context, int layoutResource) {
super(context, layoutResource);
// find your layout components
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());
ToastMsg.toastmsg(mContext,String.valueOf("values"+e.getY()));
// this will perform necessary layouting
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;
}
}
从 Fragment 调用 CustomMarkerView 类
IMarker marker = new CustomMarkerView(this.getContext(), R.layout.barchart_marker_view_layout);
mBarChart.setMarker(marker);
mBarChart.setDrawMarkers(true);
【问题讨论】: