0% found this document useful (0 votes)
37 views3 pages

Practical No13

This document contains code for an Android application that displays a circular progress bar. The activity_main.xml layout file defines a RelativeLayout containing a ProgressBar and TextView. The circular_progress_bar.xml and circular_shape.xml files define drawables for the circular progress bar and its background shape. The MainActivity.java code finds the ProgressBar and TextView, then uses a Handler to incrementally increase the progress bar's value and update the text over time.

Uploaded by

sajid shaikh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views3 pages

Practical No13

This document contains code for an Android application that displays a circular progress bar. The activity_main.xml layout file defines a RelativeLayout containing a ProgressBar and TextView. The circular_progress_bar.xml and circular_shape.xml files define drawables for the circular progress bar and its background shape. The MainActivity.java code finds the ProgressBar and TextView, then uses a Handler to incrementally increase the progress bar's value and update the text over time.

Uploaded by

sajid shaikh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Practical No.

13
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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:gravity="center_horizontal"
android:orientation="vertical"
tools:context=".MainActivity">
<RelativeLayout
android:id="@+id/progress_layout"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_margin="100dp">
<ProgressBar
android:id="@+id/progress_bar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/circular_shape"
android:indeterminate="false"
android:progressDrawable="@drawable/circular_progress_bar"
android:textAlignment="center" />
<TextView
android:id="@+id/progress_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:gravity="center"
android:text="---"
android:textColor="@color/colorPrimary"
android:textSize="28sp"
android:textStyle="bold" />
</RelativeLayout>
</LinearLayout>
circular_progress_bar.xml:
<?xml version="1.0" encoding="utf-8"?>
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="270"
android:toDegrees="270">
<shape
android:innerRadiusRatio="2.5"
android:shape="ring"
android:thickness="8dp"
android:useLevel="true">
<gradient
android:angle="0"
android:endColor="@color/colorPrimary"
android:startColor="#000000"
android:type="sweep"
android:useLevel="false" />
</shape>
</rotate>

circular_shape.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:innerRadiusRatio="2.5"
android:shape="ring"
android:thickness="3dp"
android:useLevel="false">
<solid android:color="@color/colorPrimary" />
</shape>

MainActivity.java:
package com.example.pr13;
import android.os.Bundle;
import android.os.Handler;
import android.widget.ProgressBar;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
private ProgressBar progressBar;
private TextView progressText;
int i = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
progressBar = findViewById(R.id.progress_bar);
progressText = findViewById(R.id.progress_text);
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
if (i <= 100) {
progressText.setText("" + i);
progressBar.setProgress(i);
i++;
handler.postDelayed(this, 200);
} else {
handler.removeCallbacks(this);
}
}
}, 200);
}
}

Output:

You might also like