Android仿简书创作弹起弹框
主要是弹框由上往下和由下往上的动画进入效果
一、思路:
定义动画效果的xml
二、效果图:
看视频更直观点:
Android开发轮子-仿简书创作弹起弹框
三、关键代码:
java
public class DialogUtils {
public static AlertDialog getAlertDialog(Context context) {
return new AlertDialog.Builder(context, R.style.mydialog).setCancelable(true).create();
}
public static Dialog showTopDialog(final Context mContext){
final AlertDialog dialog = getAlertDialog(mContext);
dialog.show();
final Window window = dialog.getWindow();
window.setGravity(Gravity.TOP);
window.setContentView(R.layout.dialog_create);
window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT);
window.setWindowAnimations(R.style.AnimTop);
return dialog;
}
public static Dialog showBottomDialog(final Context mContext){
final AlertDialog dialog = getAlertDialog(mContext);
dialog.show();
final Window window = dialog.getWindow();
window.setGravity(Gravity.BOTTOM);
window.setContentView(R.layout.dialog_create);
window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT);
window.setWindowAnimations(R.style.AnimBottom);
return dialog;
}
}
四、项目demo源码结构图:
有问题或者完整源码demo的私信我,我每天都看私信的