title: Right Alignment for Spinner via Java (Not via XML)
body: <p><strong>Spinners need to be Right aligned on the Screen</strong></p>
  
  <p>I tried to use everything like setGravity and other, Nothing worked.</p>
  
  <p>I tried to search also a lot for this Right alignment, everywhere solution is available in <strong>XML</strong> format but <strong>NOT</strong> in Java format.
  Can someone Please help :)</p>
  
  <p><a href="https://i.stack.imgur.com/tG4ps.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tG4ps.png" alt="Spinner needs to be Right side of the screen"></a></p>
  
  <p>Code</p>
  
  <pre><code>        final LinearLayout lm = (LinearLayout) findViewById(R.id.linearLayout1);
          LinearLayout ll = new LinearLayout(this);
          ll.setOrientation(LinearLayout.HORIZONTAL);
  
          final Spinner spinner = new Spinner(this);
          spinner.setOnItemSelectedListener(this);
          ArrayAdapter&lt;String&gt; dataAdapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_spinner_item, categories);
          dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
          spinner.setAdapter(dataAdapter);
          spinner.setEnabled(false);
          ll.addView(spinner);
          lm.addView(ll); 
  </code></pre>
  
  <p>Abir : Now its showing this.</p>
  
  <p><a href="https://i.stack.imgur.com/958SV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/958SV.png" alt="enter image description here"></a></p>