提示:本站收集StackOverFlow近2千万问答,支持中英文搜索,鼠标放在语句上弹窗显示对应的参考中文或英文, 本站还提供 中文繁体 英文版本 中英对照 版本,有任何建议请联系yoyou2525@163.com。
我正在使用 MpAndroidChart 并使用自定义标记创建条形图。 我在标记中有两个 TextView,但其中只有一个正在显示数据。 第一个是唯一显示数据的。 但是,如果我在 getOffset() 覆盖中放置一个断点,然后评估表达式 tvDateTime.getText(),则文本设置在第二个 TextView 中。
public class MyMarkerView extends MarkerView {
private TextView tvSensorData, tvDateTime;
private ArrayList<String[]> tooltipTxtsArr;
public MyMarkerView(Context context, int layoutResource, ArrayList<String[]> tooltipTxt) {
super(context, layoutResource);
// this markerview only displays a textview
tvSensorData = findViewById(R.id.sensorData);
tvDateTime = findViewById(R.id.dateTime);
tooltipTxtsArr = tooltipTxt;
}
// callbacks every time the MarkerView is redrawn, can be used to update the
// content (user-interface)
@Override
public void refreshContent(Entry e, Highlight highlight) {
//TODO:
// set the entry-value as the display text
Integer ix = (int) e.getX();
String[] textData = tooltipTxtsArr.get(ix);
tvSensorData.setText(textData[0]);
tvDateTime.setText(textData[1]);
}
private MPPointF mOffset;
@Override
public MPPointF getOffset() {
if (mOffset == null) {
int markerH = getHeight();
int markerW = getWidth();
// center the marker horizontally
mOffset = new MPPointF(-(markerW/ 2), -(markerH));
}
return mOffset;
}
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="121dp"
android:layout_height="80dp"
android:background="@drawable/marker_background_gray"
android:padding="7dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="21dp"
android:orientation="vertical"
>
<TextView
android:id="@+id/sensorData"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="4dp"
android:text=""
android:textSize="12dp"
android:textColor="#444444"
android:textStyle="bold"
android:layout_gravity="center_horizontal"
android:ellipsize="end"
android:singleLine="true"
/>
<TextView
android:id="@+id/dateTime"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text=""
android:textSize="12dp"
android:textColor="#444444"
android:ellipsize="end"
android:singleLine="false"
/>
</LinearLayout>
</RelativeLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.