1. Android 当中的进度条
2. 各种进度条之间的关系
3. ProgressBar进度条的风格
4. ProgressBar的使用方法
1. Android 当中的进度条
2. 各种进度条之间的关系
3. ProgressBar进度条的风格
4. ProgressBar的使用方法
1 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 xmlns:tools="http://schemas.android.com/tools" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 android:paddingBottom="@dimen/activity_vertical_margin" 6 android:paddingLeft="@dimen/activity_horizontal_margin" 7 android:paddingRight="@dimen/activity_horizontal_margin" 8 android:paddingTop="@dimen/activity_vertical_margin" 9 tools:context="first.pack.MainActivity$PlaceholderFragment" > 10 11 <ProgressBar 12 android:id="@+id/firstProgreeBar" 13 android:layout_width="match_parent" 14 android:layout_height="wrap_content" 15 style="?android:attr/progressBarStyleHorizontal" //设置风格的方法 16 /> 17 18 </RelativeLayout>
更多设置,在xml文件中设置
1 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 xmlns:tools="http://schemas.android.com/tools" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 android:paddingBottom="@dimen/activity_vertical_margin" 6 android:paddingLeft="@dimen/activity_horizontal_margin" 7 android:paddingRight="@dimen/activity_horizontal_margin" 8 android:paddingTop="@dimen/activity_vertical_margin" 9 tools:context="first.pack.MainActivity$PlaceholderFragment" > 10 11 <ProgressBar 12 android:id="@+id/firstProgreeBar" 13 android:layout_width="match_parent" 14 android:layout_height="wrap_content" 15 android:max = "200" //总量 16 android:progress="100" //当前进度 17 android:secondaryProgress="150" //第二进度, 类似解压缩时两个进度 18 style="?android:attr/progressBarStyleHorizontal" 19 /> 20 21 </RelativeLayout>
在代码中设置进度条的方法
1 public static class PlaceholderFragment extends Fragment { 2 3 private ProgressBar progressBar; 4 5 public PlaceholderFragment() { 6 } 7 8 @Override 9 public View onCreateView(LayoutInflater inflater, ViewGroup container, 10 Bundle savedInstanceState) { 11 View rootView = inflater.inflate(R.layout.fragment_main, container, false); 12 13 progressBar = (ProgressBar)rootView.findViewById(R.id.firstProgreeBar); 14 15 progressBar.setMax(50); 16 progressBar.setProgress(10); 17 progressBar.setSecondaryProgress(40); 18 19 return rootView; 20 } 21 }
更多设置
1 public static class PlaceholderFragment extends Fragment { 2 3 private ProgressBar progressBar; 4 5 public PlaceholderFragment() { 6 } 7 8 @Override 9 public View onCreateView(LayoutInflater inflater, ViewGroup container, 10 Bundle savedInstanceState) { 11 View rootView = inflater.inflate(R.layout.fragment_main, container, false); 12 13 progressBar = (ProgressBar)rootView.findViewById(R.id.firstProgreeBar); 14 15 progressBar.setMax(50); 16 progressBar.setProgress(10); 17 progressBar.setSecondaryProgress(40); 18 19 progressBar.incrementProgressBy(10); //现有基础上增加10 20 21 Boolean flag = progressBar.isIndeterminate(); //判断是否是确定的进度, 像圆圈转圈的就不是确定进度 22 23 return rootView; 24 } 25 }