条形图标记中可以有两个TextViews吗?

时间:2019-09-18 21:55:49

标签: android mpandroidchart

我正在使用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>



0 个答案:

没有答案