Question

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);
            }
Was it helpful?

Solution

That's because you use a FrameLayout view. Try LinearLayout with vertical orientation and everything will be fine.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top