最近做了一個項目,大量的用到了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點擊這裏下載!