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
448 views
in Technique[技术] by (71.8m points)

Android - displaying text in center of progress bar

I have already made a horizontal progress bar and it works perfectly. I would like to display a textview or something similar right in the middle of it showing a countdown as the bar is loading. Keep in mind its not a progress dialog, progress bar resides inside an activity and shows a countdown timer. Can anyone help me out, whats the best way to do this and how can I accomplish this?

question from:https://stackoverflow.com/questions/18410984/android-displaying-text-in-center-of-progress-bar

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

1 Reply

0 votes
by (71.8m points)

If your ProgressBar and TextView are inside a RelativeLayout you can give the ProgressBar an id, and then align the TextView with the ProgressBar using that. It should then show on top of the ProgressBar. Make sure the background is transparent so that you can still see the ProgressBar

For example:

<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:layout_width="match_parent"
        android:layout_height="match_parent"
        // other attributes
        android:id="@+id/PROGRESS_BAR"
    >
    <TextView
        android:background="#00000000" // transparent
        // other attributes
        android:layout_alignLeft="@id/PROGRESS_BAR"
        android:layout_alignTop="@id/PROGRESS_BAR"
        android:layout_alignRight="@id/PROGRESS_BAR"
        android:layout_alignBottom="@id/PROGRESS_BAR"
    >
</RelativeLayout>

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

...