Android仿简书创作弹起弹框

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的私信我,我每天都看私信的

相关推荐
俩个逗号。。9 小时前
Kotlin flow 详解
android·开发语言·kotlin
橙光成长11 小时前
android-ad-cleaner:android免 Root 批量关闭系统开屏与营销推送
android·1024程序员节
深圳雨林凯AI11 小时前
图案裂变的底色衰减:alpha通道、亮度对比与白墨分色的量化拆解
android
mmsx11 小时前
Android 模块化收口:能力组合框架、手写 LifecycleOwner 与热修复共存
android
恋猫de小郭14 小时前
Flutter 可以更直接地调用原生 API 了,Dart Direct Native Interop
android·前端·flutter
2501_9160088914 小时前
iPhone 设备信息查看,用 KeyMob 看型号、序列号、电池健康和 UDID
android·ios·小程序·https·uni-app·iphone·webview
好的佩奇1 天前
蓝牙之通信架构
android·flutter·蓝牙
FlightYe1 天前
视界原理之3D视频(四):裸眼、眼镜和头显
android·linux·c++·3d·ffmpeg·音视频
诸神黄昏EX1 天前
Android fw BatteryService
android
alexhilton1 天前
提升 Android Compose 页面的流畅度
android·kotlin·android jetpack