Loading screen / Loading screen

2

How to make a screen similar to that on android? Making the bar fill

    
asked by anonymous 03.10.2016 / 04:57

2 answers

2

Try this:

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

        }
    }

}
    
03.10.2016 / 15:26
0

Use ProgressBar, with indeterminateOnly true, and style Widget.ProgressBar.Horizontal, like this:

<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 place as background, to customize the layout

Font

    
03.10.2016 / 14:50