title: Incorrectly displayed view created programmatically (android)
body: <p>I create some views programmatically, but on some  devices they are displayed wrong. I have Layout in which i programmatically add spinner. This is my xml:</p>
  
  <p><code>container</code> - it's layout where i create spinner (programmatically)</p>
  
  <p><code>spinnerL</code> - here i add spinner</p>
  
  <pre><code>&lt;LinearLayout
          android:id="@+id/container"
          android:layout_width="match_parent"
          android:orientation="horizontal"
          android:background="#26ffffff"
          android:layout_height="wrap_content"&gt;
  
          &lt;LinearLayout
              android:id="@+id/spinnerL"
              android:orientation="horizontal"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:layout_alignParentTop="true"
              android:layout_weight="0.2"
              android:layout_centerHorizontal="true" /&gt;
  
          &lt;RelativeLayout
              android:id="@+id/spinnerOpen"
              android:layout_width="match_parent"
              android:layout_marginRight="5dp"
              android:layout_weight="0.8"
              android:layout_height="match_parent"&gt;
  
              &lt;ImageView
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:id="@+id/spinnerImage"
                  android:layout_centerVertical="true"
                  android:layout_centerHorizontal="true" /&gt;
  
  
  
          &lt;/RelativeLayout&gt;
  
      &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Here i create and add the spinner:</p>
  
  <pre><code>//here i set margins
  View linearLayoutG = convertView.findViewById(R.id.container);
  
  linearLayoutG.setBackgroundColor(Color.parseColor("#26ffffff"));
  
  LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
  
  layoutParams.setMargins(10, 0, 10, 30);
  linearLayoutG.setLayoutParams(layoutParams);
  
  //here i create spinner
  View linearLayout = convertView.findViewById(R.id.spinnerL);
  final Spinner spinner = new Spinner(context);
  
  spinner.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
  
  //code
  
  ((LinearLayout) linearLayout).addView(spinner);
  </code></pre>
  
  <p>(sorry about links, i don't have 15 reputation)</p>
  
  <p>Result on <a href="https://i.stack.imgur.com/E2zk7.jpg" rel="nofollow noreferrer">android 4.0.1</a></p>
  
  <p>Result on <a href="https://i.stack.imgur.com/fTkTi.jpg" rel="nofollow noreferrer">android 5+</a></p>
  
  <p>If i use static size, like this:</p>
  
  <pre><code>LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
              LinearLayout.LayoutParams.MATCH_PARENT, 120);
  </code></pre>
  
  <p>Here's what happens </p>
  
  <p>Result on <a href="https://i.stack.imgur.com/s6BMR.jpg" rel="nofollow noreferrer">android 4.0.1</a></p>
  
  <p>Result on <a href="https://i.stack.imgur.com/pMpFZ.jpg" rel="nofollow noreferrer">android 5+</a></p>