android之Progress
16lz
2021-01-23
一、Progress:表示进度条,本程序在标题栏和Activaty中分别加入进度条。
二、XML重要属性
android:progressBarStyle:默认进度条样式
android:progressBarStyleHorizontal:水平样式
三、重要方法
getMax():返回这个进度条的范围的上限
getProgress():返回进度
getSecondaryProgress():返回次要进度
incrementProgressBy(int diff):指定增加的进度
isIndeterminate():指示进度条是否在不确定模式下
setIndeterminate(boolean indeterminate):设置不确定模式下
setVisibility(int v):设置该进度条是否可视
四、重要事件
onSizeChanged(int w, int h, int oldw, int oldh):当进度值改变时引发此事件
效果图:
layout中的xml文件:
- <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical"
- android:background="#00ff00">
- <ProgressBar
- android:id="@+id/myProgressBar"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- style="?android:attr/progressBarStyleSmall" //设置进度条的模式为圆圈旋转模式
- />
- <ProgressBar
- android:id="@+id/myProgressBar2"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- style="?android:attr/progressBarStyleHorizontal"//设置进度条的模式为水平模式
- android:max="100" //设置进度条的最大值
- android:progress="20"//设置进度条的当前值
- android:secondaryProgress="50"//设置进度条的次进度值
- />
- </LinearLayout>
Activaty.java文件
- packagecom.cheng.progressbarproject;
- importandroid.os.Bundle;
- importandroid.app.Activity;
- importandroid.view.Menu;
- importandroid.view.Window;
- publicclassProgressBarActivityextendsActivity{
- @Override
- protectedvoidonCreate(BundlesavedInstanceState){
- super.onCreate(savedInstanceState);
- //在窗口标题栏上加进度条,这条语句必须写在super.setContentView(R.layout.main);之前
- requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
- super.setContentView(R.layout.main);
- //设置标题栏上的进度条是可见的
- setProgressBarIndeterminateVisibility(true);
- }
- @Override
- publicbooleanonCreateOptionsMenu(Menumenu){
- //Inflatethemenu;thisaddsitemstotheactionbarifitispresent.
- getMenuInflater().inflate(R.menu.main,menu);
- returntrue;
- }
- }
更多相关文章
- Android 虚拟摇杆,多种模式回调,返回距离级别,方向,角度。
- 【转】善用Android预定义样式来为我们的布局设置效果,大大节约代
- 使用ProgressBar显示进度条
- 【Android学习入门】Android中activity的启动模式
- android 设置布局为无标题样式
- Android 1.5: 飞行模式分析
- android 设计模式相关内容
- 高德地图自定义点聚合样式Android
- android 加载模式