【Android弹窗】Dialog Bottom Translate Animation
创始人
2024-04-30 19:12:09
0

文章目录

  • 1. 系统Dialog
  • 2. 自定义Dialog
  • 3. 其余

1. 系统Dialog

首先先来使用回顾一下系统的Dialog弹窗,这里使用比较简单的AlertDialog为例:

AlertDialog.Builder builder = new AlertDialog.Builder(this).setTitle("弹窗标题").setMessage("弹窗内容部分").setPositiveButton("确定", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialogInterface, int i) {dialogInterface.dismiss();}}).setNegativeButton("取消", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialogInterface, int i) {dialogInterface.dismiss();}})// 窗口消失的回调.setOnDismissListener(new DialogInterface.OnDismissListener() {@Overridepublic void onDismiss(DialogInterface dialogInterface) {Toast.makeText(SplashScreenActivity.this, "dismiss", Toast.LENGTH_SHORT).show();}})// 设置点击Dialog外区域可关闭.setCancelable(true);
AlertDialog alertDialog = builder.create();
alertDialog.show();

在这里插入图片描述
当然还有其余的Dialog,这里只是作为一个引子。注意到,在进行builder的时候有一个.setView()方法,这里来尝试一下:

.setView(R.layout.test_dialog);

布局设置为:


在这里插入图片描述
比较有意思的是加入到了Dialog的下面,那么不妨看看是如何添加的。

// AlertController
// 传递资源id,然后进行实例化
customView = inflater.inflate(mViewLayoutResId, customPanel, false);
// add View
final FrameLayout custom = (FrameLayout) mWindow.findViewById(R.id.custom);custom.addView(customView, new LayoutParams(MATCH_PARENT, MATCH_PARENT));

那么应该也是预留了一个位置FrameLayout

2. 自定义Dialog

定义一个类,继承自AppCompatDialog或者Dialog,然后进行一些相关的设置:

public class DialogDemo extends AppCompatDialog {private ICancelListener mCancelListener;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.share_layout_demo);dialogSetting();initView();}private void initView() {TextView cancelButton = findViewById(R.id.share_cancel);if (cancelButton != null) {cancelButton.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {DialogDemo.this.dismiss();if (mCancelListener != null) {mCancelListener.onCancelSelected();}}});}}/*** 配置Dialog*/private void dialogSetting() {WindowManager.LayoutParams params = getWindow().getAttributes();params.width = ViewGroup.LayoutParams.MATCH_PARENT;params.height = ViewGroup.LayoutParams.WRAP_CONTENT;// 定义Dialog在底部params.gravity = Gravity.BOTTOM;getWindow().setAttributes(params);// 设置外部区域点击可取消setCancelable(true);setCanceledOnTouchOutside(true);}public DialogDemo(Context context, ICancelListener listener) {// 设置Dialog的样式R.style.share_dialogsuper(context, R.style.share_dialog);this.mCancelListener = listener;}public void setCancelListener(ICancelListener listener) {this.mCancelListener = listener;}
}

设置Dialog的样式R.style.share_dialog,这里添加了对应的进入动画:


对应的slide_into样式,定义了对应的位移动画translate




至于slide_down对应的反着就行。效果:
在这里插入图片描述
至于面板希望填充其余的内容,那就自定义即可。这里主要是记录一下这个位移动画的使用,使用了accelerate_decelerate_interpolator插值器。

3. 其余

发现每次录屏mp4文件转gif还是挺麻烦的,期望写一个小控制台工具来搞定这件事,留个坑。

相关内容

热门资讯

监控摄像头接入GB28181平... 流程简介将监控摄像头的视频在网站和APP中直播,要解决的几个问题是:1&...
Windows10添加群晖磁盘... 在使用群晖NAS时,我们需要通过本地映射的方式把NAS映射成本地的一块磁盘使用。 通过...
protocol buffer... 目录 目录 什么是protocol buffer 1.protobuf 1.1安装  1.2使用...
在Word、WPS中插入AxM... 引言 我最近需要写一些文章,在排版时发现AxMath插入的公式竟然会导致行间距异常&#...
【PdgCntEditor】解... 一、问题背景 大部分的图书对应的PDF,目录中的页码并非PDF中直接索引的页码...
Fluent中创建监测点 1 概述某些仿真问题,需要创建监测点,用于获取空间定点的数据࿰...
educoder数据结构与算法...                                                   ...
MySQL下载和安装(Wind... 前言:刚换了一台电脑,里面所有东西都需要重新配置,习惯了所...
修复 爱普生 EPSON L4... L4151 L4153 L4156 L4158 L4163 L4165 L4166 L4168 L4...
MFC文件操作  MFC提供了一个文件操作的基类CFile,这个类提供了一个没有缓存的二进制格式的磁盘...