Android 底部弹出Dialog(横向满屏)
项目中经常需要底部弹出框,这里我整理一下其中我用的比较顺手的一个方式(底部弹出一个横向满屏的dialog)。
效果图如下所示(只显示关键部分):

步骤如下所示:
1.定义一个dialog的布局(lay_share.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="match_parent"
android:background="@color/white"
android:orientation="vertical"> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingBottom="@dimen/padding_15"
android:paddingTop="@dimen/padding_15"> <View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" /> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawablePadding="@dimen/padding_5"
android:drawableTop="@mipmap/ic_weixin_share"
android:gravity="center"
android:text="微信"
android:textColor="@color/color_999999"
android:textSize="@dimen/text_14" /> <View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" /> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawablePadding="@dimen/padding_5"
android:drawableTop="@mipmap/ic_circle_share"
android:gravity="center"
android:text="朋友圈"
android:textColor="@color/color_999999"
android:textSize="@dimen/text_14" /> <View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" /> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawablePadding="@dimen/padding_5"
android:drawableTop="@mipmap/ic_weibo_share"
android:gravity="center"
android:text="微博"
android:textColor="@color/color_999999"
android:textSize="@dimen/text_14" /> <View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout> <View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:layout_marginLeft="@dimen/padding_10"
android:layout_marginRight="@dimen/padding_10"
android:background="@color/color_c9c9c9" /> <TextView
android:id="@+id/tv_cancel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="@dimen/padding_15"
android:text="取消"
android:textColor="@color/color_666666"
android:textSize="@dimen/text_18" />
</LinearLayout>
2.定义弹出框弹出动画(dialog_enter.xml)
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="300"
android:fromYDelta="100%p"
android:toYDelta="0" />
</set>
dialog_enter.xml
3.定义弹出框隐藏动画(dialog_exit.xml)
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="300"
android:fromYDelta="0"
android:toYDelta="100%p" />
</set>
dialog_exit.xml
4.定义动画style
<!--弹出框动画-->
<style name="share_animation" parent="android:Animation">
<item name="android:windowEnterAnimation">@anim/dialog_enter</item>
<item name="android:windowExitAnimation">@anim/dialog_exit</item>
</style>
5.定义对话框样式
<!-- 对话框样式 -->
<style name="dialog_bottom_full" parent="android:style/Theme.Dialog">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:scrollHorizontally">true</item>
</style>
6.最后,在需要从底部弹出dialog的地方,直接调用showDialog()方法
/**
* 显示分享弹出框
*/
private void showDialog() {
if (mShareDialog == null) {
initShareDialog();
}
mShareDialog.show();
} /**
* 初始化分享弹出框
*/
private void initShareDialog() {
mShareDialog = new Dialog(this, R.style.dialog_bottom_full);
mShareDialog.setCanceledOnTouchOutside(true);
mShareDialog.setCancelable(true);
Window window = mShareDialog.getWindow();
window.setGravity(Gravity.BOTTOM);
window.setWindowAnimations(R.style.share_animation);
View view = View.inflate(this, R.layout.lay_share, null);
view.findViewById(R.id.tv_cancel).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (mShareDialog != null && mShareDialog.isShowing()) {
mShareDialog.dismiss();
}
}
});
window.setContentView(view);
window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);//设置横向全屏
}
大功告成!
收工!
Android 底部弹出Dialog(横向满屏)的更多相关文章
- (转)android底部弹出iOS7风格对话选项框(QQ对话框)--第三方开源--IOS_Dialog_Library
本文转载于:http://blog.csdn.net/zhangphil/article/details/44940339 完成这个效果的是使用了 IOS_Dialog_Library 下载地址:ht ...
- android 闹钟提醒并且在锁屏下弹出Dialog对话框并播放铃声和震动
android 闹钟提醒并且在锁屏下弹出Dialog对话框并播放铃声和震动 1.先简单设置一个闹钟提醒事件: //设置闹钟 mSetting.setOnClickListener ...
- Android Demo---实现从底部弹出窗口
在前面的博文中,小编简单的介绍了如何制作圆角的按钮以及圆角的图片,伴着键盘和手指之间的舞步,迎来新的问题,不知道小伙伴有没有这样的经历,以App为例,点击头像的时候,会从底部弹出一个窗口,有从相册中选 ...
- 转 android 从底部弹出一个popuwindow,渐入渐出效果。我这里是用在购物车需要选择购买选项的操作。
最近要改客户端,需要实现一个从底部弹出的popuwindow,像我这种渣渣android技术,能整出popuwindow但是整不出动画,百度之,记录一下. 从下面这个地址转的 http://blog. ...
- android不依赖具体activity弹出Dialog对话框,即全局性对话框
最近在DialogUtil类中声明了一个静态的弹出Dialog方法,弹出的Dialog也是静态的,并且只在第一次进行创建,由于Dialog弹出依附于Activity,所以就出现了问题. 即:第一次调用 ...
- Android BottomSheet:底部弹出Fragment面板(4)
Android BottomSheet:底部弹出Fragment面板(4) BottomSheet不仅可以弹出轻量级的定制好的面板(见附录文章5,6,7),还可以弹出"重"的 ...
- Android屏幕底部弹出DialogFragment(3)
Android屏幕底部弹出DialogFragment(3) 附录文章1,2的DialogFragment是常规的DialogFragment,但是现在的一些Android开发中,往往需要从底部 ...
- 关于一条定制长按Power键弹出Dialog的需求
如题,需要定制长按Power键弹出的Dialog,UI上的大致效果是:全屏,中间下拉按钮“Swipe Down To Power Off”下拉关机,底部左右两侧“Reboot”,“Cancel”按钮, ...
- 拍照选择图片(Activity底部弹出)
效果图如下: 第一步 : 显示出的布局文件:alert_dialog.xml <?xml version="1.0" encoding="utf-8"?& ...
随机推荐
- Topshelf 学习 跨平台
Topshelf是一个开源的跨平台的宿主服务框架,支持Windows和Mono,只需要几行代码就可以构建一个很方便使用的服务宿主. 官网:http://topshelf-project.com Git ...
- 快速Android开发系列网络篇之Volley
Volley是Google推出的一个网络请求库,已经被放到了Android源码中,地址在这里,先看使用方法 RequestQueue mRequestQueue = Volley.newRequest ...
- 使用google 语言 api 来实现整个网站的翻译
---恢复内容开始--- 使用google 语言 api 来实现整个网站的翻译,这时我们可以利用免费的google api来做处理来实现多语言的功能. 放在 HTML 文件中 <div id=& ...
- git revert和reset区别
1.在github上建立测试项目并克隆到本地 2.本地中新建两个文本文件 3.将a.txt commit并push到远程仓库 执行 git add a.txt, git commit -m " ...
- Vertica数据库常用管理命令汇总
1.查询数据库是否有等待 select * from resource_queues where node_name=(select node_name from nodes order by nod ...
- MVP社区巡讲-云端基础架构:12月5日北京站 12月12日上海站
紧跟当今的技术发展趋势还远远不够,我们要引领变革!加入本地技术专家社区,获取真实案例.实况培训演示以及探讨新一代解决方案.在此活动中,您将: 了解如何运用开源(OSS)技术.Microsoft 技术及 ...
- Android GradientDrawable(shape标签定义) 静态使用和动态使用(圆角,渐变实现)
Android GradientDrawable使用优势: 1. 快速实现一些基本图形(线,矩形,圆,椭圆,圆环) 2. 快速实现一些圆角,渐变,阴影等效果 3. 代替图片设置为View的背景 4. ...
- 用eclipse开发项目时遇到的常见错误整理,和配套解决方案(1)
01. MyEclipse项目导入eclipse后,怎么发布不了? 今天导入了之前的一个MyEclipse项目,更改jdk后,发现发布不了.解决方案如下: 打开项目根目录,找到.settings文件夹 ...
- AR创意分享:儿童涂鸦遇上程序绘图
第一节 临摹 小明经常临摹同桌小美的画作. 美术课上,老师表扬了小美的新作. 图1.1 小美的作品<蒙娜·毛虫的微笑> 临,是照着原作画:摹,是用薄纸张蒙在原作上面画. 第二节 借画 小明 ...
- 货架工程项目之js dom实现项目工程进度图
笔者最近要负责有个项目工程网站的安装进度过程,实现的效果要求大概如下图所示 由于笔者没有参与到数据库的制作,得知他们这个项目设计工序的时候就一个开始日期的和完成日期,连整个项目的安装结束时间都没有简直 ...