在Android的fingertouch上绘制editview/textview

在Android的fingertouch上绘制editview/textview,android,Android,我是安卓系统的新手,在我的应用程序中,我需要在手指触摸上绘制textview/editview,用户可以输入。我搜索了很多,但没有找到相关内容 我找到了绘制editview/文本的链接,但没有在fingertouch上找到 您可以通过在视图上注册触摸事件来实现这一点。当触发触摸事件时,您可以基于触摸事件坐标创建EditText/TextView class YourMainClass extends Activity{ public void onCreate(Bundle bundle)

我是安卓系统的新手,在我的应用程序中,我需要在手指触摸上绘制textview/editview,用户可以输入。我搜索了很多,但没有找到相关内容


我找到了绘制editview/文本的链接,但没有在fingertouch上找到

您可以通过在视图上注册触摸事件来实现这一点。当触发触摸事件时,您可以基于触摸事件坐标创建EditText/TextView

class YourMainClass extends Activity{

  public void onCreate(Bundle bundle)
  {
     //Do your normal UI initialization here
     your_layout.setOnTouchListener(new TouchListener()); //where your_layout is the layout/view of your Activity that should register the touch events.
  }

  class TouchListener implements OnTouchListener
  {
     @Override
     public boolean onTouch(View v, MotionEvent event) {
         if(event.getAction() == MotionEvent.ACTION_UP) {
           RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT); //See note below
           params.leftMargin = (int)event.getX() - v.getLeft();
           params.topMargin = (int)event.getY() - v.getTop();
           EditText edit = new EditText(this);
           edit.setLayoutParams(params);
           your_layout.addView(edit);
           return true;
         }
     }
  }
}
注意:请确保将LayoutParams类型更改为您使用的布局类型(例如:LinearLayout.LayoutParams,如果您使用LinearLayout放置编辑文本)


另外,如果使用填充,实际编辑文本的坐标可能会关闭(因为在使用
v.getLeft()
v.getTop()
时,填充区域仍算作视图,但在将编辑文本添加到布局中时则不算作视图)。

什么是“fingertouch”?你的意思是当用户触摸文本视图时,你希望键盘弹出吗?没问题。如果上述示例有效,请确保向上投票/接受,以便更多人看到:)