How to display text in the center of an undefined ProgressBar (spinning wheel)?

How to display text in the center of an undefined ProgressBar (spinning wheel)?

I want to display seconds in the center. Using android API-19. The docs say that you need to use a horizontal bar to display progress. However, if I can display the text in the center, then this will work for me.

So how do I set up the text to display in the spinning wheel travel bar?

(I'd rather try using the existing API before starting to create a custom progress bar)

<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"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.mycom.countdowntimer.CountdownMainActivity$PlaceholderFragment" >

    <ProgressBar
        android:id="@+id/progressBar1"
        android:indeterminate="true"
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="87dp" />   
</RelativeLayout>

      

+4


source to share


2 answers


Add this text to layout

  <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="5 s"
    android:id="@+id/txt_secondsleft"
    android:layout_alignRight="@+id/progressBar1"
    android:layout_alignLeft="@+id/progressBar1"
    android:gravity="center"
    android:layout_alignBottom="@+id/progressBar1"
    android:layout_alignTop="@+id/progressBar1"
   />

      



You can use it to display the text you want and it will focus on your progress bar

+7


source


I tried and found a solution. Use xml, It will align the text in the center of the wheel. Hope this helps you.



 <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

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

        <ProgressBar
            android:id="@+id/prograss_bar"
            style="@android:style/Widget.ProgressBar.Large"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </LinearLayout>

    <TextView
        android:id="@+id/progress"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:text="loading" />
</RelativeLayout>

      

+2


source







All Articles