效果展示

UI设计想让我实现这样一个弹窗效果,点击中部+号,可以出现一个弹窗,同时可供进一步跳转。
先看最后完成的效果。

为了实现这个效果,主要拆解成几个部分:弹窗绘制、弹窗逻辑编写、弹窗动画

弹窗绘制

首先绘制三个弹窗中的按钮形状
button_circle3.xml

<?xml version="1.0" encoding="UTF-8"?>
<shapexmlns:android="http://schemas.android.com/apk/res/android"android:shape="rectangle"><!-- 填充的颜色 --><solid android:color="@color/bar" /><cornersandroid:radius="25dip" />
</shape>

之后,构建弹窗文件主体
diglog_j.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:background="@drawable/dialog_bk"android:orientation="vertical"android:layout_marginLeft="50dp"android:layout_marginRight="50dp"><Buttonandroid:id="@+id/btn_fabu"android:layout_width="180dp"android:layout_height="wrap_content"android:background="@drawable/button_circle3"android:gravity="center"android:text="发布商品"android:textStyle="bold"android:textColor="@color/white"android:textSize="22sp"android:layout_marginRight="32dp"android:layout_marginLeft="32dp"android:layout_marginTop="50dp"android:paddingLeft="10dp"android:paddingRight="10dp"android:layout_gravity="center"/><Buttonandroid:id="@+id/btn_dingzhi"android:layout_width="180dp"android:layout_height="wrap_content"android:background="@drawable/button_circle3"android:gravity="center"android:text="定制方案"android:textStyle="bold"android:textColor="@color/white"android:textSize="22sp"android:layout_marginRight="32dp"android:layout_marginLeft="32dp"android:layout_marginTop="30dp"android:paddingLeft="10dp"android:paddingRight="10dp"android:layout_gravity="center"/><Buttonandroid:id="@+id/btn_renling"android:layout_width="180dp"android:layout_height="wrap_content"android:background="@drawable/button_circle3"android:gravity="center"android:text="认领小羊"android:textStyle="bold"android:textColor="@color/white"android:textSize="22sp"android:layout_marginRight="32dp"android:layout_marginLeft="32dp"android:layout_marginTop="30dp"android:paddingLeft="10dp"android:paddingRight="10dp"android:layout_gravity="center"android:layout_marginBottom="50dp"/>
</LinearLayout>

最后绘制弹窗框的形状
dialog_bk.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"><item><layer-list><!-- SHADOW LAYER --><item android:top="4dp"><shape><solid android:color="@color/black" /><corners android:radius="30dip"/></shape></item><!-- CONTENT LAYER --><item android:top="12dp"><shape><solid android:color="@color/white" /><cornersandroid:topLeftRadius="20dp"android:topRightRadius="20dp" /><strokeandroid:width="1dp"android:color="@color/me_blue"/></shape></item></layer-list></item>
</selector>

这里比较巧妙的是绘制弹窗框的顶部阴影,使用了两层shape,让第一层往下偏移,实现阴影效果。
再勾勒1dp的蓝色边框,使用stroke关键字

至此,弹窗绘制完成。

弹窗逻辑

弹窗逻辑包含两个部分,一个是弹出逻辑,这部分Dialog已经做了足够的封装,调用相关API即可。另一个是弹窗内按钮的监听和跳转。
这两部分统一写在show_dialog函数中。

private void show_dialog(){dialog = new Dialog(this, R.style.ActionSheetDialogStyle);//填充对话框的布局inflate = LayoutInflater.from(this).inflate(R.layout.dialog_j, null);//获取控件Button btn_fabu = inflate.findViewById(R.id.btn_fabu);//取消Button btn_dingzhi = inflate.findViewById(R.id.btn_dingzhi);//支付宝支付Button btn_renling = inflate.findViewById(R.id.btn_renling);//添加银行卡//将布局设置给Dialogdialog.setContentView(inflate);//获取当前Activity所在的窗体Window dialogWindow = dialog.getWindow();//设置Dialog从窗体底部弹出dialogWindow.setGravity(Gravity.BOTTOM);//获得窗体的属性WindowManager.LayoutParams lp = dialogWindow.getAttributes();lp.y = 0;//设置Dialog距离底部的距离//宽度填充当前布局文件宽度lp.width = WindowManager.LayoutParams.WRAP_CONTENT;//将属性设置给窗体dialogWindow.setAttributes(lp);dialog.show();//显示对话框btn_fabu.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {Intent i = new Intent(MainActivity.this, fabushangpin.class);startActivity(i);}});btn_dingzhi.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {Intent i = new Intent(MainActivity.this, dingzhi.class);startActivity(i);}});btn_renling.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {Intent i = new Intent(MainActivity.this, renling.class);startActivity(i);}});}

弹窗动画

弹窗动画包括两部分,一个是弹窗的效果,即后面的背景变暗;另一个是从下到上的弹出效果。
在上面的函数中,引用了 R.style.ActionSheetDialogStyle,该文件就包含弹窗效果。

在themes.xml中添加

  <style name="ActionSheetDialogStyle" parent="@android:style/Theme.Dialog"><!-- 背景透明 --><item name="android:windowBackground">@android:color/transparent</item><item name="android:windowContentOverlay">@null</item><!-- 浮于Activity之上 --><item name="android:windowIsFloating">true</item><!-- 边框 --><item name="android:windowFrame">@null</item><!-- Dialog以外的区域模糊效果 --><item name="android:backgroundDimEnabled">true</item><!-- 无标题 --><item name="android:windowNoTitle">true</item><!-- 半透明 --><item name="android:windowIsTranslucent">true</item><!-- Dialog进入及退出动画 --><item name="android:windowAnimationStyle">@style/ActionSheetDialogAnimation</item></style><!-- ActionSheet进出动画 --><style name="ActionSheetDialogAnimation" parent="@android:style/Animation.Dialog"><item name="android:windowEnterAnimation">@anim/actionsheet_dialog_in</item><item name="android:windowExitAnimation">@anim/actionsheet_dialog_out</item></style>

进出动画
actionsheet_dialog_in.xml

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"android:duration="200"android:fromYDelta="100%"android:toYDelta="0" />

actionsheet_dialog_out.xml

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"android:duration="200"android:fromYDelta="0"android:toYDelta="100%" />

至此,效果完成。

参考资料

https://blog.csdn.net/juer2017/article/details/79012028

Android:实现弹窗效果相关推荐

  1. android通讯录效果,Android通讯录中的弹窗效果

    通讯录索引效果,网上很多了,我这里做个记录. 相信大家都体验过android通讯录中的弹窗效果.如图所示: android中提供了QuickContactBadge来实现这一效果.这里简单演示下. 理 ...

  2. Android模块功能系列(1)一底部Tab标签以及照相、相册弹窗效果

    请尊重个人劳动成果,转载注明出处,谢谢! http://blog.csdn.net/xiaxiazaizai01/article/details/52109039 经常见群里有童鞋问如何实现底部Tab ...

  3. 半透明背景Activity实现AlertDialog弹窗效果

    用半透明背景Activity实现AlertDialog弹窗效果的原因是,用小米手机测试项目时,发现工具类中的AlertDialog弹窗无法弹出,查阅资料才知道小米工程师为了防止有人作恶禁用了这项功能. ...

  4. TDialog: DialogFragment封装,高效实现各种弹窗效果.md

    前言 文章代码示例已放到Github上了,有需要的朋友可以去看下TDialog,欢迎star和fork,项目会一直维护,有疑问可以提Issues或留言. 文章目录 TDialog框架的由来 框架使用解 ...

  5. android 下拉窗帘,Android 窗帘(Curtain)效果二之波浪式动态扭曲效果

    上一篇文章已经实现了如何把一张图片扭曲成波浪效果,那么这一篇文章我们介绍如何动态调整系数,去改变波浪图片的皱褶成度.我们自一次观察下图morning routine的效果: 仔细观察我们发现,当往右滑 ...

  6. Android m 自定义下拉菜单,Android实现动画效果的自定义下拉菜单功能

    我们在购物APP里面设置收货地址时,都会有让我们选择省份及城市的下拉菜单项.今天我将使用Android原生的 Spinner 控件来实现一个自定义的下拉菜单功能,并配上一个透明渐变动画效果. 要实现的 ...

  7. 给页面字段中添加一个按钮,点击按钮实现弹窗效果

    页面效果: 点击按钮后弹窗效果: 点击左上角搜索框效果: 页面实现代码 首先配置一个入住房间字段 <field><header>入住房间</header><d ...

  8. EXT中创建一个弹窗效果

    调用弹窗的代码 第一种弹窗:一级弹窗 二级弹窗: 第二种弹窗:一级弹窗 二级弹窗: 我是写在了一个方法中来触发弹窗,也可以写一个事件来触发 //触发第一种弹窗代码window.setPassWord4 ...

  9. easyui带表单的弹窗效果制作

    带表单的弹窗效果制作 点击[增加]按钮,弹出带表单的窗口. <!DOCTYPE html> <html><head><meta charset="U ...

  10. android 卡片旋转动画,Android 卡片翻转效果

    Android 卡片翻转效果使用的Cramre来完成 记录一下: 一个好用的3D旋转工具类 oid.graphics.Matrix; import android.util.Log; import a ...

最新文章

  1. activity切换动画特效
  2. mysql 5.1 备份_mysql 5.1备份到5.0 USING BTREE
  3. [转]C++结构体|类 内存对齐详解
  4. Android 的全盘加密容易破解
  5. mysql英文介绍_每日科技英文48: MySQL C API简介
  6. Codeforces Round #594 (Div. 2) C. Ivan the Fool and the Probability Theory 思维 + dp
  7. C语言指针转换为intptr_t类型
  8. tomcat中间件的默认端口号_Tomcat下载安装及配置
  9. 【B站免费教程】2W 收藏!火爆 B 站的计算机科学速成教程发布,全中文版
  10. ZZULIOJ 1067: 有问题的里程表
  11. 向量点积衡量相似度_向量点积与叉积
  12. html dt和dd顺序,dl dt dd使用方法
  13. 表格与合并之Excel如何快速合并多个表格数据
  14. 计算机中浮点数的表示,浮点数在计算机中的表示
  15. 梦幻西游网络诊断找不到服务器,《梦幻西游》电脑版出现网络故障 受影响者可寻找恢复使者进行恢复...
  16. 最严“22条措施”打击市场乱象 云南旅游“浴火重生”
  17. Linux安装库时安装源错误,linux环境下golang安装第三方库的时候出错的决办法
  18. 宋晓丽20190912-3 词频统计
  19. 小程序统一服务消息_小程序客服消息接入微信教程
  20. 基于STM32F103——AS608指纹模块+串口打印

热门文章

  1. 网络是怎样连接的学习笔记1----探索浏览器内部(十分适合理清思路)
  2. C语言课设物业费管理系统(大作业)
  3. linux基础期末考,Linux基础期末考试试题.pdf
  4. [OrCad电路板设计系统].Orcad.Pspice.9.2下载安装
  5. UML用例图分析——铁路售票系统
  6. 系统分析师考试经验分享
  7. mac 安装adb工具
  8. 单链表---建立基本学生信息管理系统
  9. android地图偏移谷歌中国地图偏移校正补丁,关于谷歌地图GPS偏移问题的解决办法...
  10. C语言实现密码字典生成器