0

Hi I know that there are similar questions, and I am sorry for repeating, but they are not working on my case. I have a progress bar that works perfectly OK, but the problem is that I need to display the progress value on the right side of the progress.

I tried these solutions: Progressbar along with text in Android and Align TextView with the progress of progressbar

My code:

private void setProgressBar(int progress) {
    binding.progressbar.setScaleY(15f);
    binding.progressbar.setMax(18);
    binding.progressbar.setMin(0);
    binding.progressbar.setProgress(progress);

    if (progress > 0) {
        binding.progressTV.setY(progress);
    }

    // int xPosition=  (((binding.progressbar.getRight() - binding.progressbar.getLeft()) / binding.progressbar.getMax()) * binding.progressbar.getProgress() ) + binding.progressbar.getLeft();
    //
    // binding.progressTV.setTranslationX((float)xPosition - ((float)binding.progressTV.getWidth()/2));
    // binding.progressTV.setText(String.valueOf(progress));
}

My XML:

 <RelativeLayout
     android:id="@+id/relatve_layout"
     android:layout_width="0dp"
     android:layout_height="wrap_content"
     app:layout_constraintBottom_toBottomOf="parent"
     app:layout_constraintEnd_toEndOf="parent"
     app:layout_constraintStart_toStartOf="parent"
     app:layout_constraintTop_toBottomOf="@+id/age_until_18_TV" >

     <ProgressBar
         android:id="@+id/progressbar"
         style="@style/MyProgressBar"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:paddingStart="8dp"
         android:paddingEnd="8dp" />

     <TextView
         android:id="@+id/progress_TV"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="@string/current_age_value"
         android:textColor="@color/property_fees"
         android:textSize="12sp"
         android:paddingBottom="2dp"
         android:layout_alignStart="@id/progressbar"
         android:layout_alignTop="@id/progressbar"
         android:layout_alignEnd="@id/progressbar"
         android:layout_alignBottom="@id/progressbar"/>   
 </RelativeLayout>

and my style:

<style name="MyProgressBar" parent="@style/Widget.AppCompat.ProgressBar.Horizontal">
    <item name="android:progressBackgroundTint">#97a5f7</item>
    <item name="android:progressTint">#4d88ff</item>
</style>

I need to make this EDIT: enter image description here

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
gojic
  • 363
  • 7
  • 20
  • Hello, Could you add how it looks? – rguzman Dec 23 '20 at 13:59
  • What is this mean by? `But the problem is that i need to display progress on right side of progress.` If my expectation is right you can use custom dialog like this https://stackoverflow.com/a/55344053/2462531 – Shailendra Madda Dec 23 '20 at 14:02
  • @ShailendraMadda i added what is suppose to looks like.My number does not show itself like that,It does not follow a progress it's always in front my progress bar . – gojic Dec 23 '20 at 14:17

0 Answers0