반응형
출처 - http://baeksupervisor.tistory.com/72
중요한 것은 xml 이다.
백날 progress item 태그에 android:drawable 속성에 이미지를 지정해봐야 소용 없다는 것!!!!
clip 태그에 줘야 한다.
>>> StartUp.java <<<
package com.cs.android; import android.app.Activity; import android.os.Bundle; import android.widget.ProgressBar; import android.widget.TextView; public class StartUp extends Activity { private static ProgressBar bar_time = null; private static ProgressBar bar_percent = null; private static TextView tv1 = null; private static TextView tv2 = null; private StartUpTask task = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); tv1 = (TextView)findViewById(R.id.tv1); tv2 = (TextView)findViewById(R.id.tv2); bar_time = (ProgressBar)findViewById(R.id.bar_time); bar_time.setProgressDrawable(getResources().getDrawable(R.drawable.custom_progress_time)); bar_time.setProgress(0); bar_percent = (ProgressBar)findViewById(R.id.bar_percent); bar_percent.setProgressDrawable(getResources().getDrawable(R.drawable.custom_progress_percent)); bar_percent.setProgress(0); task = new StartUpTask(tv1, tv2); ProgressBar[] bars = new ProgressBar[2]; bars[0] = bar_time; bars[1] = bar_percent; task.execute(bars); } }>>> StartUpTask.java <<<
package com.cs.android; import android.os.AsyncTask; import android.widget.ProgressBar; import android.widget.TextView; public class StartUpTask extends AsyncTask{ ProgressBar bar1 = null; ProgressBar bar2 = null; TextView tv1 = null; TextView tv2 = null; public StartUpTask(TextView... tv) { this.tv1 = tv[0]; this.tv2 = tv[1]; } @Override protected Boolean doInBackground(ProgressBar... params) { this.bar1 = params[0]; this.bar2 = params[1]; for(int i=0 ; i<=100 ; i++) { try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } publishProgress(i); } return null; } @Override protected void onCancelled() { super.onCancelled(); } @Override protected void onPostExecute(Boolean result) { super.onPostExecute(result); tv1.setText("0s"); } @Override protected void onPreExecute() { super.onPreExecute(); tv1.setText("10s"); tv2.setText("0%"); } @Override protected void onProgressUpdate(Integer... values) { super.onProgressUpdate(values); tv1.setText(((100-values[0])/10+1)+"s"); tv2.setText(values[0]+"%"); bar1.setProgress(100-values[0]); bar2.setProgress(values[0]); } }
>>> /res/drawable-hdpi/custom_progress_*.xml <<<
>
반응형
'개발 > 안드로이드' 카테고리의 다른 글
[android]블루투스(bluetooth) 통신 (0) | 2011.05.30 |
---|---|
안드로이드 키보드 옵션 (0) | 2011.05.12 |
Manifest <activity> configChanges attribute. (0) | 2011.05.12 |
안드로이드 (android) 네트워크 프로그램 사용시 Connection Timeout 체크하기 (0) | 2011.05.03 |
WIFI 대기모드에서 돌아가게 하기 (0) | 2011.05.03 |
댓글