Simply put, I have a progress bar with text ON it, like so:
<ProgressBar
android:id="@+id/progressbar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
/>
<TextView
android:id="@+id/text_on_progressbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/progressbar"
android:layout_alignLeft="@+id/progressbar"
android:text="text"
/>
The thing is, I would like to have “text” only appear directly to the left of the current progress. So, it would be right justified to the current endpoint. Any ideas on how to do this? So the text moves alongside the progress.
So is there a way to find the pixel coordinates of the current endpoint of the displayed progress? That way I can put the textview there dynamically.
Or is there a way to actually access the progressbar.xml itself to edit this in?
You can calculate the endpoint of the displayed progress from the complete width of the view and the current progress. Easy example: If the view is 400 pixels wide and progress is 50%, the endpoint will be 50% of 400, which is 200 (plus left position of the progress view of course, e.g. margin or padding …)