Android progress bar embedded in ui and not in dia

2019-06-21 03:24发布

Is there a way to embed the progress bar in the UI with out an dialog. And not programmatically but with layout xml files. I am guessing it has to be some sort of animation or a "drawable"

2条回答
beautiful°
2楼-- · 2019-06-21 04:01

Yes you can use the Widget "ProgressBar" in your xml: http://developer.android.com/reference/android/widget/ProgressBar.html

Visual indicator of progress in some operation. Displays a bar to the user representing how far the operation has progressed; the application can change the amount of progress (modifying the length of the bar) as it moves forward. There is also a secondary progress displayable on a progress bar which is useful for displaying intermediate progress, such as the buffer level during a streaming playback progress bar.

A progress bar can also be made indeterminate. In indeterminate mode, the progress bar shows a cyclic animation. This mode is used by applications when the length of the task is unknown.

查看更多
Evening l夕情丶
3楼-- · 2019-06-21 04:07

You can use the ProgressBar widget:

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

You can customize it with your own image if you want. You just have to create a styles file (res/styles.xml) like this:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="AProgressBar">
        <item name="android:indeterminateDrawable">@drawable/progress_small</item>
        <item name="android:minWidth">20dip</item>
        <item name="android:maxWidth">20dip</item>
        <item name="android:minHeight">20dip</item>
        <item name="android:maxHeight">20dip</item>
    </style>
</resources>

@drawable/progress_small makes reference to an image file called progress_small.png. Then, just modify your progress bar this way:

<ProgressBar
    android:id="@+id/a_progressbar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    style="@style/AProgressBar"/>
查看更多
登录 后发表回答