Progressbar android with text inside

前端 未结 3 1344
慢半拍i
慢半拍i 2021-01-06 08:47

I have a circular ProgressBar, I want inside this circular bar, write the progression in percentage (like 60 %, or 70 %..)
How can I do this inside the circ

相关标签:
3条回答
  • 2021-01-06 09:14

    The onDraw way presents its own set of challenges between Android versions and devices. I have particularly liked using a RelativeLayout or FrameLayout. If need be, use styles across various dpi's for consistency in UX.

    0 讨论(0)
  • 2021-01-06 09:34

    You could achieve it overriding onDraw inside ProgressBar, and use Canvas.drawText to decide where the text should be positioned . Here you can find the documentation for drwawText:

    x and y are the coordinates of the origin of the text being drawn

    0 讨论(0)
  • 2021-01-06 09:37

    You should try this:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent" android:layout_height="match_parent" >
    
        <ProgressBar
            android:id="@+id/myProgress"
            android:layout_width="match_parent" android:layout_height="match_parent" />
    
        <TextView
            android:id="@+id/myTextProgress"
            android:layout_alignLeft="@id/myProgress" android:layout_alignTop="@id/myProgress"
            android:layout_alignRight="@id/myProgress" android:layout_alignBottom="@id/myProgress"
            android:background="@android:color/transparent" >
    
    </RelativeLayout>  
    

    You also can with the centerInParent set to true, see this.
    And see this tutorial or this one for more info to display your percentage.
    Hope this will help.

    0 讨论(0)
提交回复
热议问题