【发布时间】:2015-08-06 21:28:21
【问题描述】:
我写了自定义对话框。对话框正确显示,但在关闭时我想添加动画(slide_out_top)。对话框的重力是顶部。下面是对话框的来源:
public class MessageDialog extends Dialog {
private LinearLayout mLinearLayout;
private TextView mText;
private ImageView mAttentionImage;
private int mBackgroundColor;
private String mMessage;
private int mImage;
private Animation bottondown;
private RelativeLayout body;
public MessageDialog(Context context) {
super(context);
}
public MessageDialog(Context context, int custom_message_dialog) {
super(context);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.view_message);
WindowManager.LayoutParams wmlp = getWindow().getAttributes();
getWindow().getAttributes().windowAnimations = R.style.DialogAnimation;
wmlp.flags &= ~WindowManager.LayoutParams.FLAG_DIM_BEHIND;
wmlp.gravity = Gravity.TOP;
wmlp.width = WindowManager.LayoutParams.MATCH_PARENT;
wmlp.height = 300;
wmlp.horizontalMargin = 0;
wmlp.verticalMargin = 0;
getWindow().setBackgroundDrawableResource(android.R.color.transparent);
Animation bottomUp = AnimationUtils.loadAnimation(getContext(),
R.anim.slide_in_top);
bottondown=AnimationUtils.loadAnimation(getContext(),
R.anim.slide_out_top);
body = (RelativeLayout) findViewById(R.id.u_message_body);
//body.startAnimation(bottomUp);
mLinearLayout = (LinearLayout) findViewById(R.id.u_message_content);
mText = (TextView) findViewById(R.id.u_message_text);
mAttentionImage = (ImageView) findViewById(R.id.u_message_dialog_image);
mLinearLayout.setBackgroundColor(getContext().getResources().getColor(mBackgroundColor));
mText.setText(mMessage);
mAttentionImage.setBackgroundResource(mImage);
final Timer t = new Timer();
t.schedule(new TimerTask() {
public void run() {
try {
dismiss();
t.cancel();
} catch (Exception ex) {
}
}
}, 2000);
findViewById(R.id.u_message_dialog_close).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
}
});
}
}
这是我的动画 xml 代码
slide_in_top
<?xml version="1.0" encoding="utf-8"?>
<translate
android:duration="@android:integer/config_mediumAnimTime"
android:fromYDelta="-100%p"
android:toYDelta="0%p" />
slide_out_top.xml
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:toYDelta="10%p"
android:duration="@android:integer/config_longAnimTime" />
正如我所说,我的对话框的重力是 Top。现在我想添加 slide_out_top 动画 在我关闭对话框动画无法正常工作的那一刻
我该如何解决这个问题?
【问题讨论】:
标签: android android-animation android-dialog