I am using MpCharts library in my project. I am using custom marker in it. I am facing a problem, when I touch my graph near boundaries, marker positioning is dislocated. Here is my code:

 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;
}

}

My custom layout 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: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>

enter image description here I want my marker to come exactly on the highlighted point. It is working fine for middle values.

This is my pointer in middle which is correct

enter image description here

For boundary value it is dislocating.

Related posts

Recent Viewed