title: SeekBar - Showing progress with TextView above
body: <p>I'm trying the (surely simple?) task of having a TextView follow the thumb on a progress bar and show the progress in the TextView.</p>
  
  <p>The problem is that for progress values of less than half max, the TextView drifts to the left of the thumb, getting more and more left of the correct place and vice versa with progress values more than half max the TextView drifts more and more to the right.</p>
  
  <p>Below is a version of code that reproduces the problem...</p>
  
  <p>Layout.xml</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:orientation="vertical" 
  android:layout_height="match_parent"
  android:paddingBottom="@dimen/activity_vertical_margin"
  android:paddingLeft="@dimen/activity_horizontal_margin"
  android:paddingRight="@dimen/activity_horizontal_margin"
  android:paddingTop="@dimen/activity_vertical_margin"
  tools:context=".Seekbar_test" &gt;
  
  &lt;SeekBar
      android:id="@+id/seekBar1"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:max="59"
      android:layout_marginTop="24dp" /&gt;
  
  &lt;TextView
      android:id="@+id/textView1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:textAppearance="?android:attr/textAppearanceLarge" /&gt;
  </code></pre>
  
  <p></p>
  
  <p>And .java</p>
  
  <pre><code>package com.example.seekbar_test;
  import android.os.Bundle;
  import android.app.Activity;
  import android.view.Menu;
  import android.widget.SeekBar;
  import android.widget.SeekBar.OnSeekBarChangeListener;
  import android.widget.TextView;
  
  public class Seekbar_test extends Activity {
  SeekBar fade_seek;
  TextView fade_text;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_seekbar_test);
  
      fade_seek = (SeekBar) findViewById(R.id.seekBar1);
      fade_text = (TextView) findViewById(R.id.textView1);
  
      fade_seek.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {       
          @Override       
          public void onStopTrackingTouch(SeekBar seekBar) {            
          }       
          @Override       
          public void onStartTrackingTouch(SeekBar seekBar) {     
          }       
          @Override       
          public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {
              say_minutes_left(progress);
          }
      });
  }
  
  private void say_minutes_left(int how_many)
  {
      String what_to_say = String.valueOf(how_many);
      fade_text.setText(what_to_say);
  
      int seek_label_pos = (int)((float)(fade_seek.getMeasuredWidth()) * ((float)how_many / 60f));
      fade_text.setX(seek_label_pos);
  }
  }
  </code></pre>