1

Hello to all programmers. I try to create custom progress bar in android app. It have to look like

Custom progress bar

Is it possible to do that sort of PB, and if it yes, then how?

I'll be appreciated for all kind of help.

2 Answers2

0

You will need to create your own custom progress bar.

http://www.androiddevelopersolutions.com/2015/01/android-custom-horizontal-progress-bar.html

It's not perfect, but you will get an idea.

enter image description here

Or try this plugin SmoothProgressBar

ziLk
  • 3,120
  • 21
  • 45
0

As suggested Pratik Mohanrao Gondil I use this solution with some changes for VS XAMARIM

The part of Main.axml

<Button
  android:text="Button"
  android:id="@+id/acceptPhoneButton"
  android:minHeight="35dp"
  android:textColor="#ffffff"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:layout_marginRight="20dp"
  android:layout_marginLeft="20dp" />
<RelativeLayout
  android:id="@+id/progressLayout"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_centerInParent="true">
  <ImageView
    android:id="@+id/progressImage"
    android:src="@drawable/clip_source"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:background="@drawable/progress_row_bg" />
</RelativeLayout>

The clip_source.xml

<?xml version="1.0" encoding="utf-8" ?>
<clip xmlns:android="http://schemas.android.com/apk/res/android"
    android:clipOrientation="horizontal"
    android:drawable="@drawable/progress_row"
    android:gravity="left" />

The MainActivity code

using System.Timers;
using Android.Graphics.Drawables;
Timer _timer;
object _lock = new object();
bool phoneStatusFlag;
ImageView progressImage;
ClipDrawable mImageDrawable;
Button acceptPhoneButton;
private int mLevel = 0;
static int MAX_LEVEL = 10000;
static int LEVEL_DIFF = MAX_LEVEL/8;
protected override void OnCreate (Bundle bundle)
{
  base.OnCreate (bundle);
  SetContentView (Resource.Layout.Main);
  acceptPhoneButton = FindViewById<Button>(Resource.Id.acceptPhoneButton);
  progressImage = FindViewById<ImageView>(Resource.Id.progressImage);
  phoneStatusFlag = false;
  mImageDrawable = (ClipDrawable)progressImage.Drawable;
  mImageDrawable.SetLevel(0);
  acceptPhoneButton.Click += acceptPhone;
}
private void acceptPhone(object sender, EventArgs e)
{
  acceptPhoneButton.Visibility = ViewStates.Invisible;
  progressImage.Visibility = ViewStates.Visible;
  _timer = new Timer();
  _timer.Enabled = true;
  _timer.Interval = 1000;
  _timer.Elapsed += OnTimeEvent;
  mImageDrawable.SetLevel(0);
}
private void OnTimeEvent(object sender, ElapsedEventArgs e)
{
  RunOnUiThread(() =>
  {
    mLevel += LEVEL_DIFF;
    mImageDrawable.SetLevel(mLevel);
    CheckProgress(mImageDrawable.Level);
  });
}
private void CheckProgress(int progress)
{
  lock (_lock)
  {
    if (!phoneStatusFlag)
    {
      if (progress > MAX_LEVEL)
      {
        mLevel = 0;
        mImageDrawable.SetLevel(mLevel);
      }
    }
    else
    {
      mImageDrawable.SetLevel(0);
      _timer.Close();
    }
  }
}