ProgressBar 在安卓6.0显示fps软件不显示怎么解决

[Android开发学习27]界面控件之进度条(ProgressBar)
一、基础知识:
1.ProgressBar在界面文件XML中的布局:
&progressBar android:id=&@+id/progressbar_updown&&
&&&&&&& android:layout_width=&200dp&&&
&&&&&&& android:layout_height=&wrap_content&&
&&&&&&& style=&?android:attr/progressBarStyleHorizontal&&
&&&&&&& android:layout_gravity=&center_vertical&&&
&&&&&&& android:max=&100&&
&&&&&&& android:progress=&50&&
&&&&&&& android:secondaryProgress=&70&&&& &&&
&progressBar android:id=&@+id/progressbar_updown&
&&&&&&& android:layout_width=&200dp&
&&&&&&& android:layout_height=&wrap_content&
&&&&&&& style=&?android:attr/progressBarStyleHorizontal&
&&&&&&& android:layout_gravity=&center_vertical&
&&&&&&& android:max=&100&
&&&&&&& android:progress=&50&
&&&&&&& android:secondaryProgress=&70&&&& &&
style=&?android:attr/progressBarStyleHorizontal&&&& 设置风格为长形&&
android:max=&100&&&& 最大进度值为100&&
android:progress=&50&&& 初始化的进度值&&
android:secondaryProgress=&70& 初始化的底层第二个进度值&&
android:layout_gravity=&center_vertical&&&& 垂直居中&
style=&?android:attr/progressBarStyleHorizontal&&&& 设置风格为长形
android:max=&100&&&& 最大进度值为100
android:progress=&50&&& 初始化的进度值
android:secondaryProgress=&70& 初始化的底层第二个进度值
android:layout_gravity=&center_vertical&&&& 垂直居中
2.ProgressBar在代码文件(.java)中的控制使用:
private ProgressBar myProgressB&
//定义ProgressBar&&
myProgressBar = (ProgressBar) findViewById(R.id.progressbar_updown);&
//ProgressBar通过ID来从XML中获取&&
myProgressBar.incrementProgressBy(5);&
//ProgressBar进度值增加5&&
myProgressBar.incrementProgressBy(-5);&
//ProgressBar进度值减少5&&
myProgressBar.incrementSecondaryProgressBy(5);&
//ProgressBar背后的第二个进度条 进度值增加5&&
myProgressBar.incrementSecondaryProgressBy(-5);&
//ProgressBar背后的第二个进度条 进度值减少5&
private ProgressBar myProgressB
//定义ProgressBar
myProgressBar = (ProgressBar) findViewById(R.id.progressbar_updown);
//ProgressBar通过ID来从XML中获取
myProgressBar.incrementProgressBy(5);
//ProgressBar进度值增加5
myProgressBar.incrementProgressBy(-5);
//ProgressBar进度值减少5
myProgressBar.incrementSecondaryProgressBy(5);
//ProgressBar背后的第二个进度条 进度值增加5
myProgressBar.incrementSecondaryProgressBy(-5);
//ProgressBar背后的第二个进度条 进度值减少5
3.XML重要属性
android:progressBarStyle:默认进度条样式
android:progressBarStyleHorizontal:水平样式
4.重要方法
getMax():返回这个进度条的范围的上限&
getProgress():返回进度&
getSecondaryProgress():返回次要进度&
incrementProgressBy(int diff):指定增加的进度&
isIndeterminate():指示进度条是否在不确定模式下&
setIndeterminate(boolean indeterminate):设置不确定模式下&
setVisibility(int v):设置该进度条是否可视&
getMax():返回这个进度条的范围的上限
getProgress():返回进度
getSecondaryProgress():返回次要进度
incrementProgressBy(int diff):指定增加的进度
isIndeterminate():指示进度条是否在不确定模式下
setIndeterminate(boolean indeterminate):设置不确定模式下
setVisibility(int v):设置该进度条是否可视
二、代码展示:
1.&Activity_09\src\yan\activity_09\MainActivity.java&
package yan.activity_09;&
import android.os.B&
import android.view.V&
import android.view.View.OnClickL&
import android.widget.B&
import android.widget.ProgressB&
import android.app.A&
public class MainActivity extends Activity {&
&&& // 声明变量&&
&&& private ProgressBar firstBar =&
&&& private ProgressBar secondBar =&
&&& private Button myButton =&
&&& private int progress_vol = 0;&
&&& @Override&
&&& protected void onCreate(Bundle savedInstanceState) {&
&&&&&&& super.onCreate(savedInstanceState);&
&&&&&&& setContentView(R.layout.main);&
&&&&&&& //映射控件ID到变量&&
&&&&&&& firstBar = (ProgressBar)findViewById(R.id.firstBar);&
&&&&&&& secondBar = (ProgressBar)findViewById(R.id.secondBar);&
&&&&&&& myButton = (Button)findViewById(R.id.myButton);&
&&&&&&& myButton.setOnClickListener(new ButtonListenr());&
&&& class ButtonListenr implements OnClickListener{&
&&&&&&& @Override&
&&&&&&& public void onClick(View v) {&
&&&&&&&&&&& // TODO Auto-generated method stub&&
&&&&&&&&&&& if(0 == progress_vol)&
&&&&&&&&&&& {&
&&&&&&&&&&&&&&& // 设置进度条的最大值&&
&&&&&&&&&&&&&&& firstBar.setMax(200);&
&&&&&&&&&&&&&&& // 设置进度条为可见的状态&&
&&&&&&&&&&&&&&& firstBar.setVisibility(View.VISIBLE);&
&&&&&&&&&&&&&&& secondBar.setVisibility(View.VISIBLE);&
&&&&&&&&&&& }else if(progress_vol & firstBar.getMax()){&
&&&&&&&&&&&&&&& // 设置主进度条的当前值&&
&&&&&&&&&&&&&&& firstBar.setProgress(progress_vol);&
&&&&&&&&&&&&&&& // 设置第二进度条的当前值&&
&&&&&&&&&&&&&&& firstBar.setSecondaryProgress(progress_vol+10);&
&&&&&&&&&&&&&&& // 默认的进度条是无法显示进行的状态的&&
&&&&&&&&&&&&&&& //secondBar.setProgress(progress_vol);&&
&&&&&&&&&&& }else{&
&&&&&&&&&&&&&&& // 设置进度条为不可见的状态&&
&&&&&&&&&&&&&&& firstBar.setVisibility(View.GONE);&
&&&&&&&&&&&&&&& secondBar.setVisibility(View.GONE);&
&&&&&&&&&&& }&
&&&&&&&&&&& progress_vol +=10;&
&&&&&&& }&
package yan.activity_09;
import android.os.B
import android.view.V
import android.view.View.OnClickL
import android.widget.B
import android.widget.ProgressB
import android.app.A
public class MainActivity extends Activity {
&// 声明变量
&private ProgressBar firstBar =
&private ProgressBar secondBar =
&private Button myButton =
&private int progress_vol = 0;
&@Override
&protected void onCreate(Bundle savedInstanceState) {
&&super.onCreate(savedInstanceState);
&&setContentView(R.layout.main);
&&//映射控件ID到变量
&&firstBar = (ProgressBar)findViewById(R.id.firstBar);
&&secondBar = (ProgressBar)findViewById(R.id.secondBar);
&&myButton = (Button)findViewById(R.id.myButton);
&&myButton.setOnClickListener(new ButtonListenr());
&class ButtonListenr implements OnClickListener{
&&@Override
&&public void onClick(View v) {
&&&// TODO Auto-generated method stub
&&&if(0 == progress_vol)
&&&&// 设置进度条的最大值
&&&&firstBar.setMax(200);
&&&&// 设置进度条为可见的状态
&&&&firstBar.setVisibility(View.VISIBLE);
&&&&secondBar.setVisibility(View.VISIBLE);
&&&}else if(progress_vol & firstBar.getMax()){
&&&&// 设置主进度条的当前值
&&&&firstBar.setProgress(progress_vol);
&&&&// 设置第二进度条的当前值
&&&&firstBar.setSecondaryProgress(progress_vol+10);
&&&&// 默认的进度条是无法显示进行的状态的
&&&&//secondBar.setProgress(progress_vol);
&&&&// 设置进度条为不可见的状态
&&&&firstBar.setVisibility(View.GONE);
&&&&secondBar.setVisibility(View.GONE);
&&&progress_vol +=10;
2.&Activity_09\res\layout\main.xml&
&?xml version=&1.0& encoding=&utf-8&?&&&&
&LinearLayout xmlns:android=&&&&&
&&& android:orientation=&vertical&&&&
&&& android:layout_width=&fill_parent&&&&
&&& android:layout_height=&fill_parent&&&
&&& android:background=&#00aaaa&&&&
&& &TextView&
&&&&&&& android:id=&@+id/firstText&&&&
&&&&&&& android:text=&@string/hello_world&&&&
&&&&&&& android:gravity=&center_vertical&&&&
&&&&&&& android:textSize=&15pt&&&&
&&&&&&& android:background=&#aa0000&&&&
&&&&&&& android:layout_width=&fill_parent&&&&
&&&&&&& android:layout_height=&wrap_content&&&&
&&&&&&& android:singleLine=&true&/&&&&
&ProgressBar&
&&& android:id=&@+id/firstBar&&
&&& style=&?android:attr/progressBarStyleHorizontal&&
&&& android:layout_width=&200dp&&
&&& android:layout_height=&wrap_content&&
&&& android:visibility=&gone&&
&ProgressBar&
&&& android:id=&@+id/secondBar&&
&&& style=&?android:attr/progressBarStyle&&
&&& android:layout_width=&wrap_content&&
&&& android:layout_height=&wrap_content&&
&&& android:visibility=&gone&&
&&& android:id=&@+id/myButton&&
&&& android:layout_width=&wrap_content&&
&&& android:layout_height=&wrap_content&&
&&& android:text=&begin&&
&/LinearLayout&&&&
&?xml version=&1.0& encoding=&utf-8&?&&
&LinearLayout xmlns:android=&&&
&&& android:orientation=&vertical&&
&&& android:layout_width=&fill_parent&&
&&& android:layout_height=&fill_parent&
&android:background=&#00aaaa&&
&& &TextView
&&android:id=&@+id/firstText&&
&&android:text=&@string/hello_world&&
&&android:gravity=&center_vertical&&
&&android:textSize=&15pt&&
&&android:background=&#aa0000&&
&&android:layout_width=&fill_parent&&
&&android:layout_height=&wrap_content&&
&&android:singleLine=&true&/&&
&ProgressBar
&&& android:id=&@+id/firstBar&
&&& style=&?android:attr/progressBarStyleHorizontal&
&&& android:layout_width=&200dp&
&&& android:layout_height=&wrap_content&
&&& android:visibility=&gone&
&ProgressBar
&&& android:id=&@+id/secondBar&
&&& style=&?android:attr/progressBarStyle&
&&& android:layout_width=&wrap_content&
&&& android:layout_height=&wrap_content&
&&& android:visibility=&gone&
&&& android:id=&@+id/myButton&
&&& android:layout_width=&wrap_content&
&&& android:layout_height=&wrap_content&
&&& android:text=&begin&
&/LinearLayout&&
3.&Activity_09\res\values\strings.xml&
&?xml version=&1.0& encoding=&utf-8&?&&
&resources&&
&&& &string name=&app_name&&Activity_09&/string&&
&&& &string name=&hello_world&&Hello world!&/string&&
&&& &string name=&menu_settings&&Settings&/string&&
&/resources&&
&?xml version=&1.0& encoding=&utf-8&?&
&resources&
&&& &string name=&app_name&&Activity_09&/string&
&&& &string name=&hello_world&&Hello world!&/string&
&&& &string name=&menu_settings&&Settings&/string&
&/resources&
三、效果展示:ProgressBar 在安卓6.0不显示怎么解决
请问有没有知道ProgressBar 在安卓6.0不显示怎么解决吗?就连默认的ProgressBar 也显示不了
1,先检查一下你有没有在配置好progressdialog之后show出来
2,打log看下有没有运行到那里,或者调试
3,实在不行看一下trace文件
你还没有登录,请先登录或注册慕课网帐号
38141人关注
Copyright (C)
All Rights Reserved | 京ICP备 号-29837人阅读
android_ui(3)
android 开发小知识(7)
方式1:(效果为补间动画一样)
&ProgressBar
android:layout_width=&wrap_content&
android:layout_height=&wrap_content&
android:indeterminate=&true&
android:indeterminateDrawable=&@anim/loading& /&其中动画loading:
&?xml version=&1.0& encoding=&UTF-8&?&
&animation-list android:oneshot=&false&
xmlns:android=&/apk/res/android&&
&item android:duration=&60& android:drawable=&@drawable/load_1& /&
&item android:duration=&60& android:drawable=&@drawable/load_3& /&
&item android:duration=&60& android:drawable=&@drawable/load_5& /&
&item android:duration=&60& android:drawable=&@drawable/load_7& /&
&item android:duration=&60& android:drawable=&@drawable/load_9& /&
&item android:duration=&60& android:drawable=&@drawable/load_11& /&
&item android:duration=&60& android:drawable=&@drawable/load_13& /&
&item android:duration=&60& android:drawable=&@drawable/load_15& /&
&/animation-list&
方式2:(效果为自定义图片让其不断的旋转)
&ProgressBar
android:layout_width=&wrap_content&
android:layout_height=&wrap_content&
android:indeterminate=&true&
android:indeterminateDrawable=&@drawable/progressbar& /&其中progressbar:
&?xml version=&1.0& encoding=&utf-8&?&
&layer-list xmlns:android=&/apk/res/android& &
android:drawable=&@drawable/load&
android:fromDegrees=&0.0&
android:pivotX=&50.0%&
android:pivotY=&50.0%&
android:toDegrees=&360.0& /&
&span style=&white-space:pre&& &/span&
&!-- 其中360.0值越大,转的圈圈越快 --&
&/layer-list&
方式三:(效果为自定义颜色让其不断的旋转)
&ProgressBar
android:layout_width=&wrap_content&
android:layout_height=&wrap_content&
android:indeterminate=&true&
android:indeterminateDrawable=&@drawable/progressbar2& /&其中progressbar2:
&pre name=&code& class=&html&&&?xml version=&1.0& encoding=&utf-8&?&
&rotate xmlns:android=&/apk/res/android&
android:fromDegrees=&0&
android:pivotX=&50%&
android:pivotY=&50%&
android:toDegrees=&360& &
android:innerRadiusRatio=&3&
android:shape=&ring&
android:thicknessRatio=&8&
android:useLevel=&false& &
android:centerColor=&#FFFFFF&
android:centerY=&0.50&
android:endColor=&#1E90FF&
android:startColor=&#000000&
android:type=&sweep&
android:useLevel=&false& /&
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:128566次
积分:1713
积分:1713
排名:千里之外
原创:43篇
评论:12条
(1)(3)(6)(4)(1)(1)(1)(3)(3)(1)(1)(1)(1)(2)(9)(3)(4)(2)(1)

我要回帖

更多关于 安卓模拟器6.0系统 的文章

 

随机推荐