title: Android TextView text alignment
body: <p>I don't know how text is going to be aligned in advance. But I will be getting horizontal and vertical alignment separately. What is the best way to set the alignment programmatically. I can do something like this: </p>
  
  <pre><code>/**
   * Sets text alignment
   * @param alignment
   */
  public void setAlignment(String alignment, String vAlignment){
      if (alignment.equals("Left")){
          if (vAlignment.equals("Top"))
              setGravity(Gravity.LEFT | Gravity.TOP);
          else if (vAlignment.equals("Center"))
              setGravity(Gravity.LEFT | Gravity.CENTER);
          else if (vAlignment.equals("Bottom"))
              setGravity(Gravity.LEFT | Gravity.BOTTOM);
      }
      //same for other horizontal alignments
  </code></pre>
  
  <p>Is there any other way of doing this? I will also have to look at text justification and stretching later on, so it would be easier if I could have horizontal and vertical alignments set separately one after another. Is it possible?</p>