プログレスバーを段々減らしていくという基本的なプログラムに取り組んでいます
動作をKitKat、Lollipopでそれぞれ確認したところ、0になるまでの時間がLollipopではKitKatの二倍ほどかかってしまいました。
なぜ時間が変わってしまうのでしょうか?
色々調べてみましたが、自分の力では直すことができませんでした。
回答よろしくお願いします。
※追記 どうやら3倍ほど差がでるようです 画面サイズが関係してるのでしょうか?
ProgressBarActivity.java
lang
1 2public class ProgressBarActivity extends AppCompatActivity { 3 4 private ProgressBar mProgressBar; 5 6 private int mProgressStatus = 100; 7 8 @Override 9 protected void onCreate(Bundle savedInstanceState) { 10 super.onCreate(savedInstanceState); 11 setContentView(R.layout.activity_progress_bar); 12 this.mProgressBar = (ProgressBar) findViewById(R.id.progressBar); 13 this.mProgressBar.setMax(100); 14 new ProgressBarTask().execute(); 15 } 16 17 public class ProgressBarTask extends AsyncTask<Object, Integer, Object> { 18 19 @Override 20 protected void onPreExecute() { 21 22 } 23 24 @Override 25 protected void onCancelled() { 26 27 } 28 29 @Override 30 protected void onPostExecute(Object result) { 31 if (isCancelled()) { 32 return; 33 } 34 AlertDialog.Builder alert = new AlertDialog.Builder(ProgressBarActivity.this); 35 alert.setTitle("確認"); 36 alert.setMessage("終了しました"); 37 alert.setPositiveButton("OK", null); 38 alert.show(); 39 } 40 41 @Override 42 protected void onProgressUpdate(Integer... values) { 43 mProgressBar.setProgress(mProgressStatus); 44 } 45 46 @Override 47 protected Object doInBackground(Object... params) { 48 while (mProgressStatus > 0) { 49 if (isCancelled()) { 50 return null; 51 } 52 SystemClock.sleep(25); 53 onProgressUpdate(--mProgressStatus); 54 } 55 return null; 56 } 57 } 58} 59
activity_progress_bar.xml
lang
1<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" 3 android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" 4 android:paddingRight="@dimen/activity_horizontal_margin" 5 android:paddingTop="@dimen/activity_vertical_margin" 6 android:paddingBottom="@dimen/activity_vertical_margin" 7 tools:context="***********"> 8 9 10 <ProgressBar 11 style="?android:attr/progressBarStyleHorizontal" 12 android:layout_width="wrap_content" 13 android:layout_height="wrap_content" 14 android:id="@+id/progressBar" 15 android:layout_centerVertical="true" 16 android:layout_alignParentLeft="true" 17 android:layout_alignParentStart="true" 18 android:layout_alignParentRight="true" 19 android:layout_alignParentEnd="true" 20 android:progressDrawable="@drawable/generic_progressbar"/> 21</RelativeLayout>
generic_progressbar.xml
lang
1<?xml version="1.0" encoding="utf-8"?> 2<layer-list xmlns:android="http://schemas.android.com/apk/res/android" > 3 <item android:id="@android:id/background"> 4 <shape android:shape="rectangle" > 5 <solid android:color="@android:color/darker_gray" /> 6 </shape> 7 </item> 8 <item android:id="@android:id/progress"> 9 <clip> 10 <shape android:shape="rectangle" > 11 <solid android:color="#5F67A5" /> 12 </shape> 13 </clip> 14 </item> 15</layer-list>
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/05/19 14:03