首先先来使用回顾一下系统的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
。
定义一个类,继承自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
插值器。
发现每次录屏mp4
文件转gif
还是挺麻烦的,期望写一个小控制台工具来搞定这件事,留个坑。