如何在进度旋转器中显示数字

3

我在菜单中显示了一个进度旋转器。我想在旋转器内部显示一个数字,应该如何实现?以下是我正在执行的一些代码片段,以使进度旋转器正常工作:

public void onCreateOptionsMenu(...) {
    ...
    if (uploadCount > 0) {
        MenuItem updatingMenuItem = menu.findItem(R.id.photo_capture_action_updating);
        updatingMenuItem.setActionView(R.layout.action_progressbar);
        updatingMenuItem.expandActionView();
    } else {
        menu.removeItem(R.id.photo_capture_action_updating);
    }
}

以下是 action_progressbar.xml。
<?xml version="1.0" encoding="utf-8"?>
<ProgressBar xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/progressBar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">         
</ProgressBar>

谢谢您,

你可以使用相对布局,将TextView放在背景中,Spinner加载器放在前面。就像这个用户建议的那样,在中心加载图像的进度条:https://dev59.com/m3fZa4cB1Zd3GeqPOSsl - NetStarter
1个回答

3
你可以在进度条旁边添加一个文本视图,使用重力居中,并将其包装在帧布局中。 xml-
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/progressBarLayout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <ProgressBar
        android:id="@+id/progressBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >
    </ProgressBar>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="14" />
</FrameLayout>

希望这能解决您的问题。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接