Loading/Loading screen

Asked

Viewed 1,200 times

2

How to make a screen similar to this on android? Making the bar fill inserir a descrição da imagem aqui

2 answers

2

Try it this way:

activity_main.xml

<TextView
    android:text="Loading ... Please Wait"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/progressBar"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="36dp"
    android:id="@+id/textView" />



<ProgressBar
    style="?android:attr/progressBarStyleHorizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/progressBar"
    android:layout_alignParentTop="true"
    android:layout_alignParentStart="true"
    android:layout_marginTop="170dp" />

Mainactivity.java

public class MainActivity extends AppCompatActivity {

    ProgressBar progressBar;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


         progressBar = ProgressBar.class.cast(findViewById(R.id.progressBar));

    }

    @Override
    protected void onStart() {
        super.onStart();
        new Loader().execute((Void)null);
    }

    class Loader extends AsyncTask<Void, Void, Void> {

        private Integer update = 1;
        @Override
        protected Void doInBackground(Void... params) {

            // iteramos ate 100
            while (update <= 100){
                // Criamos um Runnable q ira mandar a atualizacao desta Thread par a tela!
                final Runnable runnable = new Runnable() {
                    @Override
                    public void run() {
                        // seta o valor atualizado na tela
                        progressBar.setProgress(update);
                    }
                };
                // executa o Runnable na ThreadUI
                runOnUiThread(runnable);
                update++;
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

            return null;

        }

        @Override
        protected void onPostExecute(Void aVoid) {
           // AQUI SERA CHAMDO AO TERMINAR DE CARREGAR

        }
    }

}

0

Use Progressbar, with the indeterminateOnly true, and with the Widget style.ProgressBar.Horizontal, thus:

<ProgressBar
    android:id="@+id/progress"
    style="?android:attr/progressBarStyleHorizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/tvProcessing"
    android:indeterminateOnly="true"/>

Style:

style="@android:style/Widget.ProgressBar.Horizontal"

And if you want to create a drawable and put as background, to customize the layout

Source

Browser other questions tagged

You are not signed in. Login or sign up in order to post.