LinearLayout is only allowing one view to be added

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


            Button btn =          


        
相关标签:
3条回答
  • 2021-01-24 01:34

    orientation of your linear layout must be horizontal. change it to vertical

    0 讨论(0)
  • 2021-01-24 01:48

    Enjoy buddy

    layout = new LinearLayout(this); 
    layout.setLayoutParams(new LayoutParams( LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
    layout.setOrientation(LinearLayout.VERTICAL);
    setContentView(layout);
    layout.setOrientation(LinearLayout.VERTICAL);
    

    Reome this addContentView(layout, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

    You have not set Oreientation , Default is Horizontal, and you have given width LayoutParams.FILL_PARENT

    0 讨论(0)
  • 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);
    
    0 讨论(0)
提交回复
热议问题