Reputation: 3207
I wish to do something like a progress bar animation in Android app.
I'm trying to make a simple line which Width increases.
This is my code:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
for(int i = 0; i < 100; i++) {
ImageView iv = (ImageView) findViewById(R.id.init_line);
LinearLayout.LayoutParams parms = new LinearLayout.LayoutParams(i, 2);
iv.setLayoutParams(parms);
try { Thread.sleep(20); }
catch(Exception e) { }
}
However is not working and it doesn't appear nothing on the screen. It would be great if you guys could give me a hand on this. Thank you very much
Upvotes: 0
Views: 234
Reputation: 1563
Android has a Predefined class for a progress bar, its in a class called ProgressDialog. It looks like this:
You can add this codes in your onCreate() and set the state of the progressDialog like this:
ProgressDialog progress = new ProgressDialog(this);
progress.setMessage("Downloading Music :) ");
progress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progress.setIndeterminate(true);
For more details you can check the Android API Documentation here
This site has a full application demo about it, you might want to check it out.
Upvotes: 1
Reputation: 1451
You might want to put your code in onResume or a method that is called when the Activity (or Fragment) is visible to the user. onCreate is called when the Activity is first created and is where you should do your static setup.
Upvotes: 0