Android 动态创建TextView时,第二个TextView不会出现

Android 动态创建TextView时,第二个TextView不会出现,android,android-linearlayout,layoutparams,Android,Android Linearlayout,Layoutparams,我正在使用下面的代码在LinearLayout中创建两个文本视图。我用这种方式来捕捉触摸事件,当按下屏幕的这个指定区域时 super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); LinearLayout layOut = (LinearLayout)findViewById(R.id.loginView); LinearLayout.LayoutParams lo

我正在使用下面的代码在LinearLayout中创建两个文本视图。我用这种方式来捕捉触摸事件,当按下屏幕的这个指定区域时

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);

    LinearLayout layOut = (LinearLayout)findViewById(R.id.loginView);

    LinearLayout.LayoutParams loginParams = new LinearLayout.LayoutParams(520, 70);
    loginParams.setMargins(120, 670, 0, 0);
    TextView loginBttn = new TextView(this);
    layOut.addView(loginBttn);
    loginBttn.setBackgroundColor(Color.GREEN);
    loginBttn.setLayoutParams(loginParams);
    loginBttn.setOnTouchListener(new View.OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            // Code touch events
        }
    });

    LinearLayout.LayoutParams forgotParams = new LinearLayout.LayoutParams(370, 40);
    forgotParams.setMargins(150, 770, 0, 0);
    TextView forgotBttn = new TextView(this);
    layOut.addView(forgotBttn);
    forgotBttn.setBackgroundColor(Color.GREEN);        
    forgotBttn.setLayoutParams(forgotParams);
    forgotBttn.setOnTouchListener(new View.OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            // Code touch events
        }
    });

我用绿色来定位他们。完成后,我会把这些线拿出来。第一个可以工作,看起来很好,但第二个没有出现,我不明白为什么

我认为它超出了屏幕范围,请尝试较低的边距和位置值 例如:


成功了,我一个接一个地忘记了,谢谢
    LinearLayout.LayoutParams loginParams = new LinearLayout.LayoutParams(50, 50);
    loginParams.setMargins(10, 10, 0, 0);
    TextView loginBttn = new TextView(this);
    layOut.addView(loginBttn);
    loginBttn.setBackgroundColor(Color.GREEN);
    loginBttn.setLayoutParams(loginParams);


    LinearLayout.LayoutParams forgotParams = new LinearLayout.LayoutParams(10, 10);
    forgotParams.setMargins(20, 20, 0, 0);
    TextView forgotBttn = new TextView(this);
    layOut.addView(forgotBttn);
    forgotBttn.setBackgroundColor(Color.GREEN);        
    forgotBttn.setLayoutParams(forgotParams);