创建一个从底部显示的对话框

if (dialog == null) {
dialog = new Dialog(context, R.style.theme_from_bottom);
View view = View.inflate(context, R.layout.udialog, null);
ImageView closeView = view.findViewById(R.id.user_contract_close_view);
Button button = view.findViewById(R.id.user_contract_im_view);
dialog.setContentView(view);
dialog.setCancelable(false); //设置自适应的方法:
WindowManager.LayoutParams dialogParams = contactDialog.getWindow().getAttributes();
dialogParams.width = WindowManager.LayoutParams.MATCH_PARENT;
dialogParams.height = WindowManager.LayoutParams.WRAP_CONTENT; //设置底部显示
dialogParams.gravity = Gravity.BOTTOM;
contactDialog.getWindow().setAttributes(dialogParams); //设置窗口大小的方法:
int with = (int) (context.getResources().getDisplayMetrics().widthPixels * 0.6)
int height = (int) (context.getResources().getDisplayMetrics().heightPixels * 0.4); //对话框重置属性
contactDialog.getWindow().setAttributes(dialogParams);
}

xml 文件

 <style name="theme_from_bottom" parent="@android:style/Theme.Dialog">
<item name="android:windowFrame">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowAnimationStyle">@style/dialog_bottom</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
</style> <style name="dialog_bottom" parent="@android:style/Animation.Dialog">
<item name="android:windowFrame">@null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowIsTranslucent">false</item>
<item name="android:windowNoTitle">true</item>
<item name="android:backgroundDimEnabled">false</item>
<item name="android:windowEnterAnimation">@anim/dialog_bottom_in</item>
<item name="android:windowExitAnimation">@anim/dialog_bottom_out</item>
</style>  动画
dialog_bottom_in
<?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"
/>
<alpha
android:interpolator="@android:anim/accelerate_interpolator"
android:fromAlpha="0.0" android:toAlpha="1.0"
android:duration="300" />
</set>
dialog_bottom_out
<?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" />
<alpha
android:interpolator="@android:anim/accelerate_interpolator"
android:fromAlpha="1.0" android:toAlpha="0.0"
android:duration="300" />
</set>

dialog自适应大小、固定大小、底部显示的更多相关文章

  1. 【转】javascript弹出固定大小的窗口页面

    来源:http://weicfprince.blog.163.com/blog/static/8441066920081010113231969/ 现在我们想弹出一个WEB窗体,让其处于屏幕的中间位置 ...

  2. fusioncharts的3D饼图固定大小和角度

    3D饼图的pieRadius和startingAngle属性 pieRadius:饼图的半径 startingAngle:饼图的角度(旋转) 在固定大小的div里面,饼图上如果显示label或者val ...

  3. JavaScript自适应调整文字大小

    JavaScript自适应调整文字大小 今天有个任务,发现页面上的数字由于太长而与其他数字重叠了.这个数字还不能像文字那样只显示一部分,必须全部显示.想了一些办法都不行,最后把超过1000变成1K,大 ...

  4. 使用SplFixedArray创建固定大小的数组

    PHP在定义数组的时候不用像C或Java一样定义数组大小,PHP数组可以根据我们的需要增长或收缩.但这种灵活性在内存使用方面带来很大的不便. 而PHP中可以使用SplFixedArray创建固定大小的 ...

  5. mui在tab选项卡中echarts图表不能动态随页面变化大小 只能固定大小

    在mui tab选项卡中一直都不能让echarts动态变化大小 只能固定大小来展示图表,网上说的window.onresize = mycharts.resize;方法根本就没有效果,后面在https ...

  6. textarea 在浏览器中固定大小和禁止拖动

    HTML 标签 textarea 在大部分浏览器中只要指定行(rows)和列(cols)属性,就可以规定 textarea 的尺寸,大小就不会改变,不过更好的办法是使用 CSS 的 height 和 ...

  7. 点击弹出固定大小的新窗口(js实现)

    <SCRIPT LANGUAGE="javascript"> <!-- window.open ('page.html') --> </SCRIPT& ...

  8. textarea 怎么固定大小,不让调整

    1:彻底禁用拖动(推荐) resize: none; 2:只是固定大小,右下角的拖动图标仍在 width: 200px; height: 100px; max-width: 200px; max-he ...

  9. Mina、Netty、Twisted一起学(三):TCP消息固定大小的前缀(Header)

    在上一篇博文中,有介绍到用换行符分割消息的方法.但是这种方法有个小问题,如果消息中本身就包含换行符,那将会将这条消息分割成两条,结果就不对了. 本文介绍另外一种消息分割方式,即上一篇博文中讲的第2条: ...

随机推荐

  1. JS中各种宽度距离小结

    js中获取各种宽度和距离,常常让我们混淆,各种浏览器的不兼容让我们很头疼,现在就在说说js中有哪些宽度和距离. 1.名词解释 screen:屏幕.这一类取到的是关于屏幕的宽度和距离,与浏览器无关,应该 ...

  2. 类System

    System类简介: 在 System 类中提供了大量的静态方法,有标准输入.标准输出和错误输出流:对外部定义的属性和环境变量的访问:加载文件和库的方法:还有快速复制数组的一部分的实用方法. 常用方法 ...

  3. dos命令的使用

    echo 百度欢迎您 >d:\1.txt F7查看执行过的命令 直接进入 D盘 d: 创建目录 md fox 在fox目录下创建子目录user md fox\user\hello1 进入到use ...

  4. VS2010主题设置及插件推荐

    本文主要写了个人使用 VS2010 的一些配置及实用插件,从而打造一个符合个人风格的开发环境. 基础设置 安装 Visual Assist X 在 VS2010 中若不安装 Visual Assist ...

  5. win10下安装ubuntu18.04

    在win10下安装Ubuntu18.04,双系统共存.Ubuntu 18.04 使用的是Gnome桌面. 查看系统的启动模式: Win+R打开运行,输入msinfo32,回车查看系统信息.在BIOS模 ...

  6. Linux学习之路3-HelloWorld

    1.window系统上创建helloworld.c文件,并编写程序 #include <stdio.h> main(){ printf("Hello World!"); ...

  7. springdata 动态查询之排序

  8. whois 查询 API

    项目介绍 免费Whois查询接口,完全开放 API接口,返回JSON格式数据(支持POST,GET方式) 网页查询接口(支持POST,GET方式) 测试接口 页面: http://whois.tt80 ...

  9. 如何规避“Flash中国特供版”

    如何规避“Flash中国特供版” 来源  http://blog.sina.com.cn/s/blog_4e1bc3e90102xn0k.html 浏览国内网站,尤其是一些很重要或者很常用,但是很落后 ...

  10. macTypeError: slice indices must be integers or None or have an index method

    一般是由于Numpy的版本太高了(1.12对此进行了调整),有的时候传入numpy array里面的索引可能是浮点数,这个时候最好检查一下索引强制转换为int类型 或者安装低版本的numpy sudo ...