[英]Translate animation with android
I am new in android. 我是android新手。 I want to use the translate animation in android.
我想在android中使用翻译动画。 I want that the red rounded image comes from center of the layout.
我希望红色的圆形图像来自布局的中心。 It comes .
它来了 。 But i want that the red rounded image comes back from the center image which color is green.
但我希望红色的圆形图像从颜色为绿色的中心图像返回。 Thanks in Advance.
提前致谢。
I would recommend you Handler and it's postDelayed method. 我建议您使用Handler,它是postDelayed方法。 So the code should look like this
所以代码应该像这样
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
if(dialog != null && dialog.isShowing())
dialog.dissmiss();
}
}, 10000);
where handler should be created on the UI thread. 应该在UI线程上创建处理程序的位置。
final AlertDialog.Builder dialog = new AlertDialog.Builder(this)
.setTitle("Auto-closing Dialog")
.setMessage("After 10 second, this dialog will be closed");
dialog.setPositiveButton("Confirm", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int whichButton) {
// tasks to do when Confirm clicked
}
});
final AlertDialog alert = dialog.create();
alert.show();
// Hide after 10 seconds
final Handler handler = new Handler();
final Runnable runnable = new Runnable() {
@Override
public void run() {
if (alert.isShowing()) {
alert.dismiss();
}
}
};
alert.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
handler.removeCallbacks(runnable);
}
});
handler.postDelayed(runnable, 10000);
Create a handler, somewhere in activity oncreate method as follows: 在活动oncreate方法中的某处创建处理程序,如下所示:
handler = new Handler();
Now, show the dialog. 现在,显示对话框。
Later use this handler to dismiss dialog after 10 seconds as follows: 稍后使用此处理程序在10秒后关闭对话框,如下所示:
handler.postDelayed(new Runnable() {
public void run() {
if (dialog.isShowing())
dialog.dismiss(); // dismiss dialog
}
}, 10000);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.