首页 > IT职业 > IT生活 > MPAndroidChat 填坑笔记
继续上一天的 MPAndroidChat 填坑记录。
首先,是自定义用来 Highlight 的 Marker。代码如下所示:
@SuppressLint("ViewConstructor")public class DescriptionChartMarkerView extends MarkerView { private TextView content; private int startIndex; public DescriptionChartMarkerView(Context context, int layoutResource) { super(context, layoutResource);
content = (TextView) findViewById(R.id.view);
} @SuppressLint("DefaultLocale") @Override
public void refreshContent(Entry e, Highlight highlight) { super.refreshContent(e, highlight);
content.setText(String.format("%d", startIndex + 1));
startIndex++;
} public void setStartIndex(int startIndex) { this.startIndex = startIndex;
}
}
在实现的过程中,需要画一个圆圈,也就有了:
一般来说,我们可以通过下面的代码来生成 Position 的位置,但是好似是不工作的:
chart.getTransformer(chart.getLineData().mDataSets.get(0).getAxisDependency()).getPixelForValues(highlights[index].getX(), highlights[index].getY());
在上一步获取位置之后,接下来就是将对应的点绘制在坐标上:
View marker = LayoutInflater.from(getContext()).inflate(R.layout.marker, view, false);
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) marker.getLayoutParams();
TextView textView = (TextView) marker.findViewById(R.id.text_view);
textView.setText(String.format("%d", i));params.leftMargin = 20params.topMargin = 20marker.setLayoutParams(params);
view.addView(marker);
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/2387/viewspace-2799920/ ,如需转载,请注明出处,否则将追究法律责任。