How to design a progress bar which starts filling from bottom to top direction in android application.
In this tutorial we are creating a vertical progress bar with the use of android:rotation=”270″ attribute. This attribute allows us to rotate any widget view into degree formation so by default our horizontal progress bar is set as 0 degree and after this attribute on horizontal progress bar it will rotate the progress bar into 270 degree format so it will look like vertical progress bar. So here is the complete step by step tutorial for Create vertical progress bar in android example tutorial.
Create vertical progress bar in android example tutorial.
Code for MainActivity.java file.
package com.verticalprogressbar_android_examples.com; import android.app.Activity; import android.graphics.Color; import android.os.Bundle; import android.os.Handler; import android.widget.ProgressBar; import android.graphics.PorterDuff; public class MainActivity extends Activity { ProgressBar VerticalProgressBar; int intValue = 0; Handler handler = new Handler(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); VerticalProgressBar = (ProgressBar)findViewById(R.id.progressBar1); // Adding colors on progress bar VerticalProgressBar.getProgressDrawable().setColorFilter(Color.CYAN, PorterDuff.Mode.SRC_IN); new Thread(new Runnable() { @Override public void run() { // TODO Auto-generated method stub while(intValue < 100) { intValue++; handler.post(new Runnable() { @Override public void run() { VerticalProgressBar.setProgress(intValue); } });try { Thread.sleep(300); } catch (InterruptedException e) { e.printStackTrace(); } } } }).start(); } }
Code for activity_main.xml layout file.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.verticalprogressbar_android_examples.com.MainActivity" >
<ProgressBar
android:id="@+id/progressBar1"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="91dp"
android:minHeight="60dp"
android:minWidth="220dp"
android:rotation="270"/>
</RelativeLayout>
Screenshot: