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

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. Fum uc M-R ko P's R

    Milr-Rabin Dodod Avlo se \(n-1\) e \(u\cdot 2^t\). hen goch'n Toizz lme \([1,n-1]\) e \(l\). cak fe ...

  2. 脚本安装Rocky版OpenStack 1控制节点+1计算节点环境部署

    视频安装指南请访问: http://39.96.203.138/wordpress/document/%E8%84%9A%E6%9C%AC%E5%AE%89%E8%A3%85rocky%E7%89%8 ...

  3. git配置ssh秘钥(公钥以及私钥)

    桌面版git,  本文以github为例,gitlab等其它托管平台一样操作 当我们将代码托管到远程平台(GitHub.gitlab等)时, 我们需要在本地使用git进行push/pull代码时,需要 ...

  4. Centos6.5 pppoe-server

    [root@localhost network-scripts]# rpm -q rp-pppoepackage rp-pppoe is not installed ----------------- ...

  5. MongoDB系列:五、MongoDB Driver使用正确的姿势连接复制集

    MongoDB复制集(Replica Set)通过存储多份数据副本来保证数据的高可靠,通过自动的主备切换机制来保证服务的高可用.但需要注意的时,连接副本集的姿势如果不对,服务高可用将不复存在. 使用复 ...

  6. qsort.c源码

    /* 版权所有(C) 1991-2019 自由软件资金会. 该文件属于是GUN C语言函数库,由Douglas C. Schmidt(schmidt@ics.uci.edu)所写. GUN C语言函数 ...

  7. cordova的常用命令

    常用命令 npm install -g cordova // 加载cordovecordova create MyApp //创建一个新的文件夹cd MyApp //找到当前目录cordova pla ...

  8. Python进阶8---面向对象基础1

    面向对象 语言的分类 Python的类 定义 class ClassName: pass class MyCalss: """A example class"& ...

  9. HNOI2019游记

    \(day~?\) 我们的老师告诉我说,你这次省选目标分:\(70\),拿不到,家法伺候.但其实,我的目标是不爆零!!! \(day~-1\) 这天晚上,我们的指导老师给我们试了一下ZJOI2019, ...

  10. JS继承以及继承的几种实现方式总结

    传统面向对象语言:继承是类与类之间的关系. 而在js中由于es6之前没有类的概念,所以继承是对象与对象之间的关系. 在js中,继承就是指使一个对象有权去访问另一个对象的能力. 比如:比如对象a能够访问 ...