问题描述:

onClick graph, display X and Y axis lines with values of X and Y on Text Label in XY Plot.

网友答案:

Firstly, Welcome To Stack Overflow!

Secondly,
I assume you mean that you want to draw the origin of the axes on the point the user pressed? Also, I'm assuming you are using a CustomView with CanvasHolder. Take Holder to be the CanvasHolder of the activity/screen. Also, I'm displaying the text using Canvas.drawText. For this, you will need a Paint in which you can set all the attributed. Refer the Canvas Documentation if you need any help with that. P.S. You can also use a textView to display your text. A Simple search will get you to that. Here is the code
Step 1+2:

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentEnd="true"
    android:layout_alignParentTop="true">

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:id="@+id/Horizontal"
        android:background="@android:color/darker_gray"/>

    <View
        android:layout_height="match_parent"
        android:layout_width="1dp"
        android:id="@+id/Vertical"
        android:background="@android:color/darker_gray"/>
</LinearLayout>

Step 3:

@Override
public boolean onTouchEvent(MotionEvent event) {
    int X = event.getX(), Y = event.getY();
    View horiz = (View) findViewById(R.id.horizontal);
    View vert = (View) findViewById(R.id.vertical);
    horiz.setY(Y);
    vert.setX(X);
}

And step 4 is very simple, I've explained it in the comment. You should be able to do it without any difficulties

Hope I Helped! :D

相关阅读:
Top