Note that there are some explanatory texts on larger screens.

plurals
  1. POButtons in linearlayout appearing vertically instead of horizontally?
    primarykey
    data
    text
    <p>I'm very new to Android and I'm trying to dynamically add buttons in my android app, the problem is that they appear vertically, while this should be horizontally.</p> <p>What I'm getting:</p> <p><img src="https://i.stack.imgur.com/q04oA.png" alt="enter image description here"></p> <p>What I'm expecting (and want):</p> <p><img src="https://i.stack.imgur.com/d6Sz2.png" alt="enter image description here"></p> <p><strong>Code I'm using:</strong></p> <p>MainActivity.java:</p> <pre><code> @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); LinearLayout ll = (LinearLayout)findViewById(R.id.main_linearlayout); for(int x = 1; x &lt;= 5 ; x++) { LinearLayout tmpLinearLayout = new LinearLayout(this); tmpLinearLayout.setOrientation(LinearLayout.VERTICAL); tmpLinearLayout.setLayoutParams( new LinearLayout.LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1.0f)); tmpLinearLayout.getLayoutParams().height = 200; ll.addView(tmpLinearLayout); for(int i = 0;i&lt;5;i++) { Button tmpButton = new Button(this); tmpButton.setText("nr:" + i +" - " + x); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1.0f); tmpLinearLayout.addView(tmpButton, lp); } } } </code></pre> <p>Layout (activity_main.xml):</p> <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:id="@+id/main_linearlayout" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" android:background="@drawable/background" android:orientation="horizontal" &gt; &lt;/LinearLayout&gt; </code></pre> <p>Can anyone explain why it does this/correct me? Thank you!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload