title: How make spacing between letters in Android TextView?
body: <p>I need make design from photoshop layout. There are some fonts on the layouts. 
  Designer gave me this fonts. But on layout in photoshop, he use spacing between letters. How i can realize this in android textView? I found one solution:</p>
  
  <p><a href="https://stackoverflow.com/questions/5133548/how-to-change-letter-spacing-in-a-textview">answer on stackoverflow</a></p>
  
  <p><a href="https://stackoverflow.com/questions/14283246/change-text-kerning-or-spacing-in-textview">answer two</a></p>
  
  <p>but if i make <code>myTextView extends TextView</code> it work wrong. If i adapt for one devise, on the device with biger display,  spacing between letters increase is not proportional.</p>
  
  <p>EDIT</p>
  
  <pre><code>public class MyTextView extends TextView {
      private float letterSpacing = 0.0f;
      private CharSequence originalText = "";
      private Typeface typeface;
  
      public MyTextView(Context context) {
          this(context, null);
          isInEditMode();
      }
  
      public MyTextView(Context context, AttributeSet attrs) {
          this(context, attrs, 0);
          isInEditMode();
      }
  
      public MyTextView(Context context, AttributeSet attrs, int defStyle) {
          super(context, attrs, defStyle);
          TypedArray attributesArray = getResources().obtainAttributes(attrs, R.styleable.MyTextView);
          letterSpacing = attributesArray.getDimension(R.styleable.MyTextView_letterSpacing, 0.0f);
          String fontName = attributesArray.getString(R.styleable.MyTextView_fontName);
          if(!this.isInEditMode()) {
              if (null == fontName) {
                  typeface = Fonts.getBlockBertholdRegular(context);
              } else {
                  typeface = Fonts.get(context, fontName);
              }
              super.setTypeface(typeface);
          }
          originalText = super.getText();
          applyLetterSpacing();
          this.invalidate();
      }
  
      public float getLetterSpacing() {
          return letterSpacing;
      }
  
      public void setLetterSpacing(float letterSpacing) {
          this.letterSpacing = letterSpacing;
          applyLetterSpacing();
      }
  
      @Override
      public void setText(CharSequence text, BufferType type) {
          originalText = text;
          applyLetterSpacing();
      }
  
      @Override
      public CharSequence getText() {
          return originalText;
      }
  
      private void applyLetterSpacing() {
          if (this == null || this.originalText == null) return;
          StringBuilder builder = new StringBuilder();
          for (int i = 0; i &lt; originalText.length(); i++) {
              String c = "" + originalText.charAt(i);
              builder.append(c.toUpperCase());
              if (i + 1 &lt; originalText.length()) {
                  builder.append("\u00A0");
              }
          }
          SpannableString finalText = new SpannableString(builder.toString());
          if (builder.toString().length() &gt; 1) {
              for (int i = 1; i &lt; builder.toString().length(); i += 2) {
                  finalText.setSpan(new ScaleXSpan((letterSpacing + 1) / 10), i, i + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
              }
          }
  
          super.setText(finalText, BufferType.SPANNABLE);
          if(!this.isInEditMode()) {
              super.setTypeface(typeface);
          }
      }
  }
  </code></pre>