自定义Dialog,实现由下而上的弹出效果(模仿QQ退出等)

方法:

public Dialog createDialog(Context context, View view) {
        Dialog mSelectPhotoDialog = null;
        mSelectPhotoDialog = new Dialog(context, R.style.transparentFrameWindowStyle);
        mSelectPhotoDialog.setContentView(view);
        Window window = mSelectPhotoDialog.getWindow();
        // 设置显示动画
        window.setWindowAnimations(R.style.select_photo_dialog_animstyle);
        WindowManager.LayoutParams wl = window.getAttributes();
        wl.x = 0;
        wl.y = getActivity().getWindowManager().getDefaultDisplay().getHeight();
        // 以下这两句是为了保证按钮可以水平满屏
        wl.width = ViewGroup.LayoutParams.MATCH_PARENT;
        wl.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        // 设置显示位置
        mSelectPhotoDialog.onWindowAttributesChanged(wl);
        // 设置点击外围解散
        mSelectPhotoDialog.setCanceledOnTouchOutside(true);

        mSelectPhotoDialog.show();
}

样式:


    <style name="select_photo_dialog_animstyle">
        <item name="android:windowEnterAnimation">@anim/photo_dialog_in_animitem>
        <item name="android:windowExitAnimation">@anim/photo_dialog_out_animitem>
    style>

    <style name="transparentFrameWindowStyle" parent="android:style/Theme.Dialog">
        <item name="android:windowBackground">@android:color/transparentitem>
    style>
动画:
(一)、photo_dialog_in_anim
xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >

    <translate
        android:duration="500"
        android:fromXDelta="0"
        android:fromYDelta="1000"
        android:toXDelta="0"
        android:toYDelta="0" />

set>

(二)、photo_dialog_out_anim

xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >

    <translate
        android:duration="500"
        android:fromXDelta="0"
        android:fromYDelta="0"
        android:toXDelta="0"
        android:toYDelta="1000" />

set>

 

转载于:https://www.cnblogs.com/hacjy/p/5126320.html

你可能感兴趣的:(自定义Dialog,实现由下而上的弹出效果(模仿QQ退出等))