Note that there are some explanatory texts on larger screens.

plurals
  1. POLayout problem with button margin
    text
    copied!<p>I have problem with organizing layout in android aplication. I'm dynamically creating buttons and adding them with this code to my layout:</p> <pre><code> LayoutInflater layoutInflater = (LayoutInflater)getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); for (int i = 0; i &lt; NO_NUMBERS; i++){ Button btn = new Button(this); btn = (Button) layoutInflater.inflate(R.layout.button, null); btn.setId(2000+i); Integer randomNumber = sort.getNumbersCopy()[i]; btn.setText(randomNumber.toString()); btn.setOnClickListener((OnClickListener) this); buttonList.addView(btn); list.add(btn); } </code></pre> <p>I'm adding it to the LinearLayout:</p> <pre><code>&lt;LinearLayout android:id="@+id/buttonlist" android:layout_alignParentLeft="true" android:layout_marginTop="185dp" android:layout_marginLeft="5dp" android:layout_marginRight="5dp" android:orientation="horizontal" android:gravity="center_horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content"&gt; &lt;/LinearLayout&gt; </code></pre> <p>and i'm importing this .xml where i'm defining button layout:</p> <pre><code>&lt;Button xmlns:android="http://schemas.android.com/apk/res/android" android:textSize="26dp" android:textStyle ="bold" android:textColor="#ffffff" android:background="@drawable/button" android:layout_marginLeft="8px" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1"/&gt; </code></pre> <p>Well, layout always ends up like this:<img src="https://i.stack.imgur.com/fCQCp.png" alt="enter image description here"></p> <p>Instead of something like this (even spce between buttons, square buttons): <img src="https://i.stack.imgur.com/UHLn9.png" alt="enter image description here"></p> <p>To summarize this: I have to:</p> <ul> <li>describe button in xml</li> <li>dynamically generate N buttons</li> <li>add properties of described button to dynamically created ones</li> <li>organize layout so it can evenly distribute buttons in buttonList with spaces between tham </li> </ul>
 

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