【发布时间】:2015-07-10 00:33:49
【问题描述】:
我正在使用下面的代码在我的 LinearLayout 中创建两个 TextView。当按下屏幕的这个指定区域时,我正在使用它们来捕捉触摸事件
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
}
});
我正在使用 Green 来定位它们。完成后,我会删除这些行。第一个工作并且看起来很好,但第二个没有出现,我不明白为什么。
【问题讨论】:
标签: android android-linearlayout layoutparams