在android中触摸屏幕时如何添加布局?

在android中触摸屏幕时如何添加布局?,android,android-layout,touch,Android,Android Layout,Touch,我的要求是,无论用户在哪里触摸屏幕,我都需要显示我的布局(使用EditText和Textview)。所以我需要做如下的事情 如何使用一个TextView和EditText 在用户触摸屏幕的次数内显示mylayout 设置触摸区域附近的布局参数 } java(我需要显示我的布局时) 在onTouch方法中。。。执行以下操作 通过id获取布局,例如 RelativeLayout RelativeLayout=(RelativeLayout)findViewById(R.id.RelativeLay

我的要求是,无论用户在哪里触摸屏幕,我都需要显示我的布局(使用
EditText
Textview
)。所以我需要做如下的事情

  • 如何使用一个
    TextView
    EditText
  • 在用户触摸屏幕的次数内显示mylayout
  • 设置触摸区域附近的布局参数
  • }

    java(我需要显示我的布局时)


    在onTouch方法中。。。执行以下操作

  • 通过id获取布局,例如

    RelativeLayout RelativeLayout=(RelativeLayout)findViewById(R.id.RelativeLayout)

  • 创建新的
    edittext
    以及您想要的任何内容

  • 将这些添加到
    relativeLayout

  • 希望一切都会明朗

    public class MyLayout extends LinearLayout {
     private TextView myTextView;
     private EditText editName;
    public MyLayout(Context context) {
        super(context);
    
        // TODO Auto-generated constructor stub
    }
    
    public class MyActivity extends Activity{
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
    
        super.onCreate(savedInstanceState);
         setContentView(R.layout.main);
         }
    
      @Override
    public boolean onTouchEvent(MotionEvent event) 
        {
           // here i need to display my layout
    }
    }