按坐标获取textview中的文本

时间:2012-04-03 11:46:01

标签: android textview

如何通过了解我在屏幕上点击的x,y坐标来获取TextView中的文本(单词)? 感谢。

1 个答案:

答案 0 :(得分:0)

检查以下代码..它与我合作正常,

   public class ProjjActivity extends Activity {

    TextView txtview;
    float X,Y;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        txtview = (TextView) findViewById(R.id.tt);

    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        // TODO Auto-generated method stub

        X = event.getX();
        Y = event.getY();

        txtview.setText("X: "+X+", Y: "+Y);
        return super.onTouchEvent(event);
    }
}

希望这可以帮助你......!