Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

android

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

I want to display seconds in the center. Using android API-19. The docs say that to show progress, horizontal bar must be used. However, if I can display text in the center, then that will work for me.

So again, how do I set the text to display in a spinning wheel progress bar?

(I would prefer to try to use the existing API before running off to build 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>
like image 947
likejudo Avatar asked Jan 10 '23 18:01

likejudo


1 Answers

Add this text to your 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 be centered on your progressbar

like image 135
Pedro Oliveira Avatar answered Jan 17 '23 17:01

Pedro Oliveira