实现Android的类似iOS的一个旋转活动指示灯 [英] implement a spinning activity indicator similar to iOS in Android
问题描述
我想实现类似于一个我已经把下面的Android纺纱活动。我相信我应该使用ProgressDialog。我的问题源于如何实际操作ProgressDialog出现类似的活动的指标。
任何的想法是值得欢迎的。链接到一个例子甚至会更好。
感谢。
重新编辑:
myProgress.java
公共类myProgress延伸活动{
/ **第一次创建活动时调用。 * /
@覆盖
公共无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.main);
ProgressDialog D =(ProgressDialog)findViewById(R.id.progres);
main.xml中
< XML版本=1.0编码=UTF-8&GT?;
< RelativeLayout的的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:ID =@ + ID / PROGRES
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:重力=中心
>
<进度
机器人:ID =@ + ID /进度
机器人:不确定=真
风格=机器人:ATTR / progressBarStyleLarge
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_centerInParent =真
/>
< / RelativeLayout的>
这是我如何实现它
这里是code
@覆盖
受保护的对话框onCreateDialog(INT ID){
开关(ID){
案例DIALOG_LOADING:
最后一个对话框对话框=新的对话框(这一点,android.R.style.Theme_Translucent);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.loading);
dialog.setCancelable(真正的);
dialog.setOnCancelListener(新OnCancelListener(){
@覆盖
公共无效OnCancel的(DialogInterface对话){
// onBack pressed();
}
});
返回对话框;
默认:
返回null;
}
};
这里是 loading.xml
< XML版本=1.0编码=UTF-8&GT?;
< RelativeLayout的的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:ID =@ + ID / PROGRES
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:重力=中心
>
<进度
机器人:不确定=真
风格=机器人:ATTR / progressBarStyleLarge
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_centerInParent =真
/>
< / RelativeLayout的>
调用对话框以
的ShowDialog(DIALOG_LOADING);
隐藏它使用
dismissDialog(DIALOG_LOADING);
更新
如果你想和自定义指标,你可以做以下的 layout.xml
- 替换
进度
与的ImageView
- 将
背景
ImageView的中到的 AnimationDrawable - 您可以开始prepareDialog 在
动画
I am trying to implement the spinning activity similar to the the one I have placed below in Android. I believe I should use the ProgressDialog. My issue arises from how to actually manipulate the ProgressDialog to appear like the activity indicator.
Any thoughts are welcome. A link to an example would even be better.
Thanks.
REEDIT:
myProgress.java
public class myProgress extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ProgressDialog d = (ProgressDialog)findViewById(R.id.progres);
main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/progres"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
>
<ProgressBar
android:id="@+id/progressBar"
android:indeterminate="true"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
/>
</RelativeLayout>
this is how i achieve it
here is the code
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case DIALOG_LOADING:
final Dialog dialog = new Dialog(this, android.R.style.Theme_Translucent);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.loading);
dialog.setCancelable(true);
dialog.setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
//onBackPressed();
}
});
return dialog;
default:
return null;
}
};
here is the loading.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/progres"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
>
<ProgressBar
android:indeterminate="true"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
/>
</RelativeLayout>
call the dialog with
showDialog(DIALOG_LOADING);
hide it using
dismissDialog(DIALOG_LOADING);
UPDATE
if you want and custom indicator you can do the following in the layout.xml.
- replace the
ProgressBar
with anImageView
- set the
background
of the ImageView to a AnimationDrawable - you can start the animation in
onPrepareDialog
这篇关于实现Android的类似iOS的一个旋转活动指示灯的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!