我在项目中使用MpCharts
库。我在其中使用自定义标记。我遇到了一个问题,当我在边界附近触摸图形时,标记位置错位了。
这是我的代码:
public class CustomMarkerView extends MarkerView {
private TextView graph_valueText;
private TextView graph_TimeText;
public CustomMarkerView(Context context, int layoutResource) {
super(context, layoutResource);
// find your layout components
graph_valueText = (TextView) findViewById(R.id.graph_valueText);
graph_TimeText = (TextView) findViewById(R.id.graph_timevalueText);
}
// content (user-interface)
@Override
public void refreshContent(Entry e, Highlight highlight) {
graph_valueText.setText("" + e.getY() );
graph_TimeText.setText("" + e.getData() );
// 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;
}
}
我的自定义布局文件:
<?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:layout_marginBottom="-5dp"
>
<com.an.customfontview.CustomTextView
android:id="@+id/graph_timevalueText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="deeeeeeeeeww"
android:visibility="visible"
android:textSize="12dp"
android:textColor="@color/white"
android:padding="@dimen/three"
android:ellipsize="end"
android:singleLine="true"
android:background="@color/app_logo_color"
android:fontFamily="@string/font_name"
android:textAppearance="?android:attr/textAppearanceSmall" />
<com.an.customfontview.CustomTextView
android:id="@+id/graph_valueText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="3dp"
android:text="deeeeeeeeeww"
android:visibility="visible"
android:textSize="10dp"
android:textColor="@color/white"
android:padding="@dimen/three"
android:ellipsize="end"
android:singleLine="true"
android:fontFamily="@string/font_name"
android:layout_below="@+id/graph_timevalueText"
android:background="@color/app_logo_color"
android:textAppearance="?android:attr/textAppearanceSmall" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_online"
android:layout_below="@id/graph_valueText"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
我希望我的标记正好位于突出显示的点上。对于中等值,它工作正常。
这是我的中间指针,是正确的
对于边界值,它正在移位。