Home > Back-end >  How to set values for Progressbar in Android
How to set values for Progressbar in Android

Time:12-26

In my application I should set 2 value for linear progressbar.
Such as below image:
enter image description here

I write below codes in XML:

<com.google.android.material.progressindicator.LinearProgressIndicator
    android:id="@ id/progress"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:indeterminate="false"
    android:max="150"
    android:rotation="180"
    android:layout_marginHorizontal="@dimen/_10mdp"
    app:indicatorColor="@color/mystic"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toStartOf="@id/rightSectionLay"
    app:layout_constraintStart_toEndOf="@ id/arrowImg"
    app:layout_constraintTop_toTopOf="parent"
    app:trackColor="@color/whileSmoke"
    app:trackCornerRadius="@dimen/_10mdp"
    app:trackThickness="@dimen/_3mdp" />

In LinearProgressIndicator just can one value, but in above image progressbar has 2 values.
One of values fill from center to right and another value fill from center to left!

I searched in Google and AndroidArsenal but not found any solution or library!

How can I use progressbar with this option?

CodePudding user response:

This is a solution using 2 progress bars, aligned back-to-back with each other. One of them is scaled -1 for the X axis, making it go from right to left.

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:gravity="center">

        
    <com.google.android.material.progressindicator.LinearProgressIndicator
        android:id="@ id/progressBarLeft"
        android:layout_width="150dp"
        android:layout_height="0dp"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        android:progress="50"
        android:scaleX="-1"
     />

        
    <com.google.android.material.progressindicator.LinearProgressIndicator
        android:id="@ id/progressBarRight"
        android:layout_width="150dp"
        android:layout_height="0dp"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        android:progress="50"
        />
</LinearLayout>
  • Related