简体   繁体   English

条形图标记中是否可以有两个 TextView?

[英]Is it possible to have two TextViews in a bar chart marker?

I am creating a barchart using MpAndroidChart and using a custom marker.我正在使用 MpAndroidChart 并使用自定义标记创建条形图。 I have two TextViews inside the marker, but only one of them is displaying the data.我在标记中有两个 TextView,但其中只有一个正在显示数据。 The first one is the only one displaying data.第一个是唯一显示数据的。 However, if I put a breakpoint in the getOffset() override, and then evaluate expression tvDateTime.getText() the text is set there in the second 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM