For AndroidTV I have created a simple seek bar and text view. I am trying to align text view of seek bar thumb and trying to move with progress.
Tried these solutions but it's not working link1, link2
Sample Code
logic to get x position of text view
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(final SeekBar seekBar, final int progress, boolean fromUser) {
if (fromUser) {
int width = seekBar.getWidth()
- seekBar.getPaddingLeft()
- seekBar.getPaddingRight();
float thumbPos = width
* seekBar.getProgress()
/ seekBar.getMax();
textView.setX(width );
}
}
}
XML
<TextView
android:id="@+id/textView"
android:layout_width="160dp"
android:layout_height="90dp"
android:layout_gravity="start"
android:background="#ffff00"/>
<SeekBar
android:id="@+id/previewSeekBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:min="1"
android:max="10"/>
</RelativeLayout>
Expected
- Textview should move with seek bar progress.
- Textview should be in the center of thumb and above seek bar like in screenshot.
- Text view should move when progress > text view width/2 && progress