Warpzit
Warpzit

Reputation: 28152

How to make an Android progressbar with rounded loaderbar?

How do you make a progressbar with rounded corner at the right side (the end), not only in the left side (the start). What I currently have is nearly the layout what I want but the progressbar loader is just a straight vertical line, I'd like to get this line rounded.

Upvotes: 1

Views: 1289

Answers (3)

Seraphim's
Seraphim's

Reputation: 12768

Found a nice link:

Custom progress bar with rounded corners

Basically it uses a custom RelativeLayout and a 9-patch approach to draw the rounded progress bar.

Upvotes: 0

Warpzit
Warpzit

Reputation: 28152

So what I ended up doing this in xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@color/white"
    android:id="@+id/splash_linear">
    <FrameLayout
        android:layout_width="144dp"
        android:layout_height="13dp"
        android:layout_gravity="center"
        android:layout_marginTop="20dp">
        <View android:id="@+id/progress_horizontal"
            android:background="@drawable/progress_background"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
        <View android:id="@+id/progress_horizontal_bar"
            android:background="@drawable/progress_bar"
            android:layout_width="0dp"
            android:layout_height="match_parent"/>
    </FrameLayout>
</LinearLayout>

Then in code:

public void updateProgress(int percent) {
    int progressBarSizeDp = 144;    // the size of the progressbar
    float scale = (float) (progressBarSizeDp/100.0);
    int progressSize = (int) (percent * scale);
    if(progressSize > progressBarSizeDp) {
        progressSize = progressBarSizeDp;
    } else if(progressSize < 20) {
        progressSize = 20;
    }

    View progressBar = (View) findViewById(R.id.progress_horizontal_bar);
    int py = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, progressSize, getResources().getDisplayMetrics());

    LayoutParams params = new FrameLayout.LayoutParams(py, LayoutParams.MATCH_PARENT);
    progressBar.setLayoutParams(params);
    View splashMain = (View) findViewById(R.id.splash_linear);
    splashMain.invalidate();
}

Upvotes: 0

user717572
user717572

Reputation: 3652

Basically you should make a custom Widget, so you can cutomize it to your taste.

Here is a tutorial on exactly what you're looking for. link!

Upvotes: 1

Related Questions