PopupWindow设置动画效果
创建popupwindow的方法
Button menu;
private void showPopupWindow() {
//设置contentView
float density = DensityUtil.Obtain(activity).density;
View contentView = LayoutInflater.from(ActivityHomeImpl.this).inflate(R.layout.activity_home_menu, null);
contentView.setBackgroundColor(0xff003333);
mPopWindow = new PopupWindow(contentView, -2, DensityUtil.round(50* density), true);//DensityUtil.round(50* density)
mPopWindow.setContentView(contentView);
//设置各个控件的点击响应
((Button)contentView.findViewById(R.id.btn1)).setOnClickListener(this);
((Button)contentView.findViewById(R.id.btn2)).setOnClickListener(this);
((Button)contentView.findViewById(R.id.btn3)).setOnClickListener(this);
((Button)contentView.findViewById(R.id.btn4)).setOnClickListener(this);
((Button)contentView.findViewById(R.id.btn5)).setOnClickListener(this);
((Button)contentView.findViewById(R.id.btn6)).setOnClickListener(this);
mPopWindow.setTouchable(true);
mPopWindow.setOutsideTouchable(true);
// 实例化一个ColorDrawable颜色为半透明
//ColorDrawable dw = new ColorDrawable(0xd0000000);
//mPopWindow.setBackgroundDrawable(dw);
// 设置背景颜色变暗
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.alpha = 0.7f;
getWindow().setAttributes(lp);
mPopWindow.setOnDismissListener(new OnDismissListener() { @Override
public void onDismiss() {
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.alpha = 1f;
getWindow().setAttributes(lp);
mPopWindow.dismiss();
}
});
// 设置popWindow的显示和消失动画
mPopWindow.setAnimationStyle(R.style.contextMenuAnim);
mPopWindow.showAsDropDown(menu);
}
popupwindow 动画
<style name="contextMenuAnim" parent="@android:style/Animation.Activity">
<item name="android:windowEnterAnimation">@anim/context_menu_enter</item>
<!-- 指定显示时的动画xml -->
<item name="android:windowExitAnimation">@anim/context_menu_exit</item>
<!-- 指定消失时的动画xml -->
</style>
activity的Theme设置
<style name="RedAppLaucherTheme" parent="AppTheme"> </style>
context_menu_enter.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" > <translate
android:duration="200"
android:fromXDelta="-100%"
android:fromYDelta="0"
android:interpolator="@android:anim/anticipate_overshoot_interpolator"
android:toXDelta="0"
android:toYDelta="0" /> </set>
context_menu_exit.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" > <translate
android:duration="200"
android:fromXDelta="0"
android:fromYDelta="0"
android:interpolator="@android:anim/overshoot_interpolator"
android:toXDelta="-100%"
android:toYDelta="0" /> </set>
布局文件activity_home_menu.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" > <LinearLayout
android:layout_width="wrap_content"
android:layout_height="50dp"
android:orientation="horizontal" > <Button
android:id="@+id/btn1"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center_vertical"
android:layout_marginLeft="5dp"
android:background="@drawable/item_connection" /> <Button
android:id="@+id/btn2"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center_vertical"
android:layout_marginLeft="5dp"
android:background="@drawable/item_disk" /> <Button
android:id="@+id/btn3"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center_vertical"
android:layout_marginLeft="5dp"
android:background="@drawable/item_upgrade" /> <Button
android:id="@+id/btn4"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center_vertical"
android:layout_marginLeft="5dp"
android:background="@drawable/item_status" /> <Button
android:id="@+id/btn5"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center_vertical"
android:layout_marginLeft="5dp"
android:background="@drawable/item_about" /> <Button
android:id="@+id/btn6"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center_vertical"
android:layout_marginLeft="5dp"
android:background="@drawable/item_setting" />
</LinearLayout> </RelativeLayout>
PopupWindow设置动画效果的更多相关文章
- Android 为PopupWindow设置动画效果
首先定义显示效果的动画文件: <?xml version="1.0" encoding="utf-8"?> <set xmlns:androi ...
- VUE - 路由跳转时设置动画效果
/* 为对应的路由跳转时设置动画效果 */ <transition name="fade"> <router-view /> & ...
- PopupWindow添加动画效果
1.定义PopupWindow弹出与消失的两个动画文件,放在anim文件夹下 popup_enter.xml <?xml version="1.0" encoding=&qu ...
- 有关ViewFlipper的使用及设置动画效果的讲解
说到左右滑动,其实实现左右滑动的方式很多,有ViewPaer,自定义实现Viewgroup,gallery等都可以达到这种效果.这里做下ViewFliper实现左右滑动的效果. 会用到以下的技术: 1 ...
- Animator 设置动画效果
1. 调节预设对象大小适中 2. 设置骨骼,修改关节 3. 拖入预设动作效果对象中 4. 将预设对象拉入场景中,并新建AnimatorController 5. 新建动作或BlendTree,设置参数 ...
- Grid布局如何设置动画效果
CS代码 新增 GridLengthAnimation继承自AnimationTimeline public class GridLengthAnimation : AnimationTimeline ...
- 一起学android之设置ListView数据显示的动画效果(24)
效果图: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaGFpX3FpbmdfeHVfa29uZw==/font/5a6L5L2T/fontsize/40 ...
- setAnimationStyle实现的popwindow显示消失的动画效果
摘要 popwindow通过setAnimationStyle(int animationStyle)函数来设置动画效果 android:windowEnterAnimation表示进入窗口动画 an ...
- Qt动画效果展示(文艺IT男)
该程序使用应用程序单窗口,主窗口继承于QMainWindow:主窗口有5个QToolButton部件(窗口底部的四个以及窗口中央的一个),单击窗口底部的QToolButton部件可以使窗口中央的那个Q ...
随机推荐
- 【u225】最优分解方案
Time Limit: 1 second Memory Limit: 128 MB [问题描述] 经过第一轮的游戏,不少同学将会获得圣诞特别礼物,但这时细心的数学课代表发现了一个问题: 留下来的人太多 ...
- 关于用什么作为dll版本号的思考
作者:朱金灿 来源:http://blog.csdn.net/clever101 一个软件模块的版本如何维护呢?毫无疑问,它需要一个版本号.通过比对版本号就知道哪个高版本,哪个是低版本了.软件模块以d ...
- WPF入门(三)->几何图形之椭圆形(EllipseGeometry)
原文:WPF入门(三)->几何图形之椭圆形(EllipseGeometry) 我们可以使用EllipseGeometry 来绘制一个椭圆或者圆形的图形 EllipseGeometry类: 表示圆 ...
- Linux初接触设置笔记01
没事装Linux尝试一下,来来回回装无数次,把刚开始需要设置的东西自己收藏一下,针对Centos7 装完Centos默认会覆盖windows引导,所以首先要做的是恢复windows的引导,如果不恢复, ...
- iOS中,MRC和ARC混编
假设一个project为MRC,当中要加入ARC的文件: 选择target -> build phases -> compile sources -> 单击ARC的文件将compil ...
- 【9112】求2的n次方的精确值
Time Limit: 1 second Memory Limit: 2 MB 问题描述 求2^n的精确值.n由用户输入,0<=n<=3232. Input 输入只有一行,一个正整数n. ...
- scala 通过apply创建类的对象
package cn.scala_base.oop.scalaobject; class Boy(name: String) { private var age: Int = 0; println(n ...
- Eclipse 学习总结
一. Eclipse 中一个普通 JavaWeb 项目的目录结构 如果项目工程中没有web.xml文件,可以手动动态添加. 右击项目 -> java EE Tools -> ...
- 【a302】&&【9306】贮油点问题
Time Limit: 1 second Memory Limit: 2 MB 问题描述 一辆重型卡车欲穿过1000公里的沙漠,卡车耗油为1升/公里,卡车总载油能力为500公升.显然卡车装 一次油是过 ...
- Android之高仿手机QQ聊天
源代码下载 转载请注明出处,谢谢! 最终版已上传.优化下拉刷新.增加来消息声音提示.主界面改成ViewPager,实现左右滑动.新增群组.最近会话显示条数,开始上班了,不再修改了.谢谢! 国庆这几天, ...