How to make a progress bar 0 to 100?

2

I wanted to know how to create that screen that applications have when they open and load , in some a logo appears, in others a bar appears that is loaded from 0 to 100. and then the app appears

What is the name of that type of activity and how could one be done? I have a video that lasts 3 seconds and I would like to put it before showing the app.

    
asked by Nicolas Schmidt 09.04.2016 в 02:14
source

1 answer

1

You can do this with a ProgressBar , This is an example:

import android.app.ProgressDialog;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

    private static String TAG = "MainActivity ";
    Button btnDescarga;
    private ProgressDialog progress;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.prueba);
        btnDescarga = (Button) findViewById(R.id.btnDescarga);
    }

    public void descargar(View view){
        progress=new ProgressDialog(this);
        progress.setMessage("Descargando algo....");
        progress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
       // progress.setIndeterminate(true);
        progress.setProgress(0);
        progress.show();

        final int totalProgressTime = 100;
        final Thread t = new Thread() {
            @Override
            public void run() {
                int jumpTime = 0;

                while(jumpTime < totalProgressTime) {
                    try {
                        jumpTime += 5;
                        progress.setProgress(jumpTime);
                        sleep(200);
                    }
                    catch (InterruptedException e) {
                      Log.e(TAG, e.getMessage());
                    }
                }
            }
        };
        t.start();
    }
}

layout_main.xml

<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:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:textSize="30dp"
        android:text="Ejemplo Progress bar" />

    <Button
        android:id="@+id/btnDescarga"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Descargar"
        android:onClick="descargar"
        android:layout_marginLeft="125dp"
        android:layout_marginStart="125dp"
        android:layout_centerVertical="true" />

</RelativeLayout>

you would have something like:

    
answered by 09.04.2016 в 02:56