Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
442 views
in Technique[技术] by (71.8m points)

android - Circular Progress Indicator ignores width/height attributes and doesn't scale

I need to fit 4 circular progress bars horizontally, like this:

enter image description here

so I decided to use new material component Circular Progress Indicator (https://material.io/components/progress-indicators/android). I spread chain these 4 progress bar in constrait layout, but them don't scale. It looks like they are still having deafult 24dp size. Even if I try to hardcode width and height to 200dp for example, the output is still small progress bar.

<com.google.android.material.progressindicator.CircularProgressIndicator
            android:id="@+id/progressBarCalories"
            style="@style/ProgressBarCircular"
            android:layout_marginTop="32dp"
            android:layout_marginStart="16dp"
            android:layout_marginEnd="6dp"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintDimensionRatio="1:1"
            app:layout_constraintHorizontal_chainStyle="spread"
            app:layout_constraintTop_toBottomOf="@id/wrapperCookingTime"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toStartOf="@id/progressBarProtein"
            tools:progress="75"/>

        <com.google.android.material.progressindicator.CircularProgressIndicator
            android:id="@+id/progressBarProtein"
            style="@style/ProgressBarCircular"
            android:layout_marginTop="32dp"
            android:layout_marginStart="6dp"
            android:layout_marginEnd="6dp"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintDimensionRatio="1:1"
            app:layout_constraintHorizontal_chainStyle="spread"
            app:layout_constraintTop_toBottomOf="@id/wrapperCookingTime"
            app:layout_constraintStart_toEndOf="@id/progressBarCalories"
            app:layout_constraintEnd_toStartOf="@id/progressBarCarbs"
            tools:progress="75"/>

        <com.google.android.material.progressindicator.CircularProgressIndicator
            android:id="@+id/progressBarCarbs"
            style="@style/ProgressBarCircular"
            android:layout_marginTop="32dp"
            android:layout_marginStart="6dp"
            android:layout_marginEnd="6dp"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintDimensionRatio="1:1"
            app:layout_constraintHorizontal_chainStyle="spread"
            app:layout_constraintTop_toBottomOf="@id/wrapperCookingTime"
            app:layout_constraintStart_toEndOf="@id/progressBarProtein"
            app:layout_constraintEnd_toStartOf="@id/progressBarFat"
            tools:progress="75"/>

        <com.google.android.material.progressindicator.CircularProgressIndicator
            android:id="@+id/progressBarFat"
            style="@style/ProgressBarCircular"
            android:layout_marginTop="32dp"
            android:layout_marginStart="6dp"
            android:layout_marginEnd="16dp"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintDimensionRatio="1:1"
            app:layout_constraintHorizontal_chainStyle="spread"
            app:layout_constraintTop_toBottomOf="@id/wrapperCookingTime"
            app:layout_constraintStart_toEndOf="@id/progressBarCarbs"
            app:layout_constraintEnd_toEndOf="parent"
            tools:progress="75"/>

        <com.google.android.material.progressindicator.CircularProgressIndicator
            android:id="@+id/progressBar"
            style="@style/ProgressBarCircular"
            android:layout_marginTop="32dp"
            app:layout_constraintWidth_min="200dp"
            android:minWidth="200dp"
            android:layout_width="200dp"
            android:layout_height="wrap_content"
            app:layout_constraintTop_toBottomOf="@id/progressBarFat"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            tools:progress="75"/>

enter image description here

question from:https://stackoverflow.com/questions/65871383/circular-progress-indicator-ignores-width-height-attributes-and-doesnt-scale

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I think that's because the maxHeight and maxWidth of the progressBar is set to 48dp in the style. You have to override it to make the bar scale.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...