Align TextView with the progress of progressbar

后端 未结 2 1588
我寻月下人不归
我寻月下人不归 2021-01-22 08:27

How can I align a TextView with the progress of a horizontal ProgressBar. I want to put a TextView right above the progress position of th

相关标签:
2条回答
  • 2021-01-22 08:51

    Calculate the x position of thumb from progressBar and apply it to textview

     var xPosition=  (((seekBar.right - seekBar.left) / seekBar.max) * seekBar.progress ) + seekBar.left
    
     progressTextView.translationX = xPosition.toFloat() - (progressTextView.width/2)
    
    0 讨论(0)
  • 2021-01-22 08:56

    In the parent layout which contains your TextView and Progress bar set the gravity to center so that it will keep both of them center alligned.

    <LinearLayout
       android:layout_width="match_parent"
       android:layout_width="wrap_content"
       android:orientation="vertical"
       android:gravity="center">
    
       <TextView
          android:layout_width="wrap_content"
          android:layout_width="wrap_content"
          android:text="Hiee"/>
    
    
       <ProgressBar
          android:layout_width="wrap_content"
          android:layout_width="wrap_content"/>
    </LinearLayout>
    
    0 讨论(0)
提交回复
热议问题