最近做了一个项目,大量的用到了Dialog,但是考虑到Dialog的弹窗比较单一,所以准备了一些基本动画,这里做一下记录!
闲话不多说,请开始我们的表演!这里先上图看一下大概有哪些东西,GIF就不用想了,忘记录屏了嘎嘎嘎.....
好了进入正文!
首先生成对象(稍后我会在下面给出BaseDialog)
BaseDialog dialog = new BaseDialog(this);
一、Dialog顶部弹出退出效果
dialog.contentView(R.layout.dialog_photo_top_bottom)
.layoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT))
.dimAmount(0.5f)
.gravity(Gravity.TOP)
.offset(0, DpToPxUtils.dpInt2px(this, 48))
.animType(BaseDialog.AnimInType.TOP)
.canceledOnTouchOutside(true).show();
二、Dialog底部弹出退出效果
dialog.contentView(R.layout.dialog_photo_top_bottom)
.gravity(Gravity.BOTTOM)
.animType(BaseDialog.AnimInType.BOTTOM)
.canceledOnTouchOutside(true).show();
//为啥这么少呢?看看是不是你想要的,比如底部弹出相册,相机之类的
三、Dialog左弹出退出效果
dialog.contentView(R.layout.dialog_photo_top_bottom)
.layoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT))
.dimAmount(0.5f)
.gravity(Gravity.LEFT | Gravity.CENTER)
.animType(BaseDialog.AnimInType.LEFT)
.canceledOnTouchOutside(true).show();
四、Dialog右弹出退出效果
dialog.contentView(R.layout.dialog_photo_top_bottom)
.layoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT))
.gravity(Gravity.RIGHT | Gravity.CENTER)
.animType(BaseDialog.AnimInType.RIGHT)
.offset(20, 0)
.canceledOnTouchOutside(true).show();
另附上xml代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@color/white"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/tv_photo"
android:layout_width="match_parent"
android:layout_height="56dp"
android:gravity="center"
android:text="拍照"
android:textSize="16sp" />
<View
android:layout_width="match_parent"
android:layout_height="0.1dp"
android:background="#e6e6e6" />
<TextView
android:id="@+id/tv_album"
android:layout_width="match_parent"
android:layout_height="56dp"
android:gravity="center"
android:text="从相册选择"
android:textSize="16sp" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="10dp"
android:background="#eaebed"/>
<TextView
android:id="@+id/tv_photo_cancel"
android:layout_width="match_parent"
android:layout_height="56dp"
android:gravity="center"
android:text="取消"
android:textSize="16sp" />
</LinearLayout>
BaseDialog点击这里下载!