生成新视图时,它们会彼此堆叠
当我单击按钮将新按钮添加到框架布局时,新按钮会堆叠在一起。知道我做错了什么吗?
public void onClick(View v) {
Button newAlarm = new Button(Hop_Timer.this);
newAlarm.setText(alarmMinutes.getText() + " Addition - Remove");
newAlarm.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
FrameLayout alarmsFrame = (FrameLayout) findViewById(R.id.display_alarms);
alarmsFrame.addView(newAlarm);
}
When I click my button for adding new buttons to a framelayout, the new buttons are stacking on top of each other. Any idea what I'm doing wrong?
public void onClick(View v) {
Button newAlarm = new Button(Hop_Timer.this);
newAlarm.setText(alarmMinutes.getText() + " Addition - Remove");
newAlarm.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
FrameLayout alarmsFrame = (FrameLayout) findViewById(R.id.display_alarms);
alarmsFrame.addView(newAlarm);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
那是因为您使用
FrameLayout
视图。尝试垂直方向的 LinearLayout ,一切都会好起来的。That's because you use a
FrameLayout
view. TryLinearLayout
with vertical orientation and everything will be fine.