LinearLayout is only allowing one view to be added

后端 未结 3 1064
北海茫月
北海茫月 2021-01-24 01:05
  layout = new LinearLayout(this);
            addContentView(layout, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));


            Button btn =          


        
3条回答
  •  Happy的楠姐
    2021-01-24 01:50

     layout = new LinearLayout(this);
    layout .setOrientation(LinearLayout.VERTICAL); // orientation vertical try  this
    
                addContentView(layout, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
    
    
                Button btn = new Button(this);
                btn.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
               btn.setText("button");
    
                layout.addView(btn);
    
                Button btn1 = new Button(this);
                btn1.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
               btn1.setText("button");
    
                layout.addView(btn1);
    

提交回复
热议问题