Allign TextView with the progress of progressbar

风流意气都作罢 提交于 2020-04-15 08:37:50

问题


How can I allign a TextView with the progress of a horizontal ProgressBar. I want to put a TextView right above the progress position of the ProgressBar. The progress might be changed. Also, I want the TextView to be kept in one line, although the text length might be changed.


回答1:


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>



回答2:


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)


来源:https://stackoverflow.com/questions/21882459/allign-textview-with-the-progress-of-progressbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!