Progress bar using drawables

I need to create a simple progress bar using the two available images. One of them, of course, is the background. The other one I need to scale according to the percentage float. Is it possible to use only Java code? I tried the setBounds () method without the possibility ...: (

thank

+5
source share
2 answers

As I am sure, you know, user elements in Android require significant effort compared to pre-compiled api. If I were to do something like this, I would create a custom class that extends the view and scales the bitmap or canvas of the bitmap inside the onDraw () method. And call PostInvalidate () for every time I need to update it. However, usually custom progress indicators run differently in Android. Instead of scaling the progress made, it simply shows part of it depending on the percentage.

For an idea of ​​how to make a custom progress indicator, see this .

+1
source

, XML-.

-, XML, , @drawable/custom_progressbar:

<ProgressBar
    style="?android:attr/progressBarStyleHorizontal"
    android:progressDrawable="@drawable/custom_progressbar"
    android:layout_width="300dp"
    android:layout_height="wrap_content"
    android:background="@drawable/progress_bar_background" >
</ProgressBar>

, @drawable/custom_progressbar , , . , Android ProgressBar.

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:id="@android:id/progress">
        <clip>
            <bitmap android:src="@drawable/progress_bar_foreground" />
        </clip>
    </item>
</layer-list>

bat .

progress progress id android: id = "@android: id/background, . , Android 9patch . , , , .

, .

+6

All Articles