我如何在Android中显示活动指标?有没有Android库给定的方法?如果不是,请让我知道用于在Android中显示活动指示器的技巧。Android活动指标?
回答
做一些这样的事
ProgressDialog mDialog = new ProgressDialog(getApplicationContext());
mDialog.setMessage("Please wait...");
mDialog.setCancelable(false);
mDialog.show();
我想显示一个活动指标,如在iphone中。是否有可能显示繁忙的图像? – 2011-02-17 06:34:05
耶是使用动画和自定义图像,但不会让用户停止选择,即用户可能会选择一些按钮,并直接到其他活动,而您正在等待回应 – ingsaurabh 2011-02-17 06:37:03
如果最终得到`WindowManager $ BadTokenException`请参阅http:///stackoverflow.com/q/1561803/650233 – 2011-05-26 18:56:53
有显示,而无需使用模式ProgressDialog活动指示灯的另外两种方式。
您可以在布局中使用ImageView并将动画应用到它。 Refer developer's site。
public void startAnimation() {
// Create an animation
RotateAnimation rotation = new RotateAnimation(
0f,
360f,
Animation.RELATIVE_TO_SELF,
0.5f,
Animation.RELATIVE_TO_SELF,
0.5f);
rotation.setDuration(1200);
rotation.setInterpolator(new LinearInterpolator());
rotation.setRepeatMode(Animation.RESTART);
rotation.setRepeatCount(Animation.INFINITE);
// and apply it to your imageview
findViewById(R.id.myActivityIndicator).startAnimation(rotation);
}
或者你可以使用XML抽拉描述的背景图像,这将有一些旋转的动画:
首先描述绘制(在IE /res/drawable/my-indicator.xml)
<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/spinner_black_76"
android:pivotX="50%"
android:pivotY="50%"
android:framesCount="12"
android:frameDuration="100" />
然后将其设置在某个视图的背景
iOS的活动指示灯在Android上最直接对应的是进度条,但设置为不定。因此,您可以将视图拖放到布局中,它将为您提供旋转动画。
<ProgressBar
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/ctrlActivityIndicator"
android:indeterminateOnly="true"
android:keepScreenOn="true"
/>
您可以使用它来指示给用户一些背景活动。
public class Mp3cutterActivity extends Activity {
MP3Class mp3obj = null;
TextView tv;
MP3Class mp3classobj = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Context thiscontext = this.getApplicationContext();
mp3classobj = new MP3Class(thiscontext);
setContentView(R.layout.main);
Button btn = (Button)findViewById(R.id.startbutton);
tv = (TextView)findViewById(R.id.textview1);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//show a wait indicator as well as the function that calls walkSdcard
try {
new SearchSdCard(Mp3cutterActivity.this).execute();
// copyProtector.doCopyProtection();
} catch (Exception e) {
System.out.println("in search SD card " + e.getMessage());
}
}
private void domp3stuff() {
// TODO Auto-generated method stub
}
});
}
}
class SearchSdCard extends AsyncTask<String, Void, Boolean> {
Context context;
public ProgressDialog dialog;
public SearchSdCard(Activity activity) {
this.context = activity;
}
protected void onPreExecute() {
dialog = new ProgressDialog(context);
dialog.setMessage("wait for a moment...");
dialog.show();
}
@Override
protected Boolean doInBackground(String... params) {
// TODO Auto-generated method stub
boolean retval = true;
mp3classobj.searchSdCard();
return retval;
}
@Override
protected void onPostExecute(Boolean result) {
// TODO Auto-generated method stub
if (dialog.isShowing()) {
dialog.dismiss();
tv.setText("mp3 cutter is an app which cuts down a chunk of memory \nfrom your sdcard by \ndeleting the .mp3 files and more \nyou were made a BAKRA :-)");
if(!result){
tv.setText("error occured !!");
}
}
}
//refer below comment for the MP3class.java file details
}
- 1. Android活动指标
- 2. 在android中显示活动指标
- 3. iOS活动指标
- 4. 活动指标swift
- 5. UISearchDisplayController活动指标
- 6. Android标签活动
- 7. Apple Watchkit活动指标
- 8. 活动指标不停止
- 9. 活动指标问题
- 10. 实施活动指标
- 11. Tkinter的活动指标?
- 12. 活动指标视图
- 13. 活动指标不动画= iphone
- 14. 活动指标只动画一次
- 15. iphone dev - 活动指标滚动表
- 16. Android活动标志问题
- 17. Android上的活动标志
- 18. Android的标签活动
- 19. android webview客户端活动指示器
- 20. iPhone上的大型活动指标
- 21. 活动的指标被加载
- 22. 自定义活动指标弹出
- 23. React Native:活动和指标跟踪库?
- 24. iOS删除所有活动指标
- 25. 你如何开始活动指标?
- 26. 活动的指标和CLLocation距离
- 27. 活动指标不适用于iOS?
- 28. iphone nsurlconnect,tableview和活动指标
- 29. 快速活动指示器和标签
- 30. 为什么活动指标不显示?
D'你的意思是这样独立的无限进度指示器就像一个在ProgressDialog使用(http://developer.android.com/guide/topics/ui/dialogs.html#ProgressDialog) – Olegas 2011-02-17 06:21:40
“活动指示灯”是非常容易混淆Android中的“Activity”类和概念...并没有意识到这可能是进度对话框/栏:-)但是,在Android中有一些东西,我不知道正确的名称,因此不能谷歌 – 2011-02-17 06:34:27