如何使用屏幕坐标操作Android OS

时间:2015-09-22 05:50:13

标签: android operating-system

我有屏幕的坐标,并且我想告诉操作系统执行操作系统应该在该坐标上的屏幕触摸上执行的操作。 就像cicret以某种方式告诉手机该怎么做。用户不直接与手机交互。 如果你知道的话,请告诉我任何事情。

1 个答案:

答案 0 :(得分:0)

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.TextView;


public class MainActivity extends Activity
{
    StringBuilder stringBuilder = new StringBuilder();
    TextView textView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        this.textView = (TextView) findViewById( R.id.strXY );
        this.textView.setText("X: ,Y: ");//texto inicial

        this.textView.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View arg0, MotionEvent arg1) {

                stringBuilder.setLength(0);

                if (arg1.getAction() == MotionEvent.ACTION_MOVE) {
                    stringBuilder.append("Moving, X:" + arg1.getX() + ", Y:" + arg1.getY());
                } 
                else {
                    stringBuilder.append("Stoped, X:" + arg1.getX() + ", Y:" + arg1.getY());
                }

                textView.setText(stringBuilder.toString());
                return true;
            }
        });
    }
}