创建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设置动画效果的更多相关文章

  1. Android 为PopupWindow设置动画效果

    首先定义显示效果的动画文件: <?xml version="1.0" encoding="utf-8"?> <set xmlns:androi ...

  2. VUE - 路由跳转时设置动画效果

    /* 为对应的路由跳转时设置动画效果 */   <transition name="fade">         <router-view />     & ...

  3. PopupWindow添加动画效果

    1.定义PopupWindow弹出与消失的两个动画文件,放在anim文件夹下 popup_enter.xml <?xml version="1.0" encoding=&qu ...

  4. 有关ViewFlipper的使用及设置动画效果的讲解

    说到左右滑动,其实实现左右滑动的方式很多,有ViewPaer,自定义实现Viewgroup,gallery等都可以达到这种效果.这里做下ViewFliper实现左右滑动的效果. 会用到以下的技术: 1 ...

  5. Animator 设置动画效果

    1. 调节预设对象大小适中 2. 设置骨骼,修改关节 3. 拖入预设动作效果对象中 4. 将预设对象拉入场景中,并新建AnimatorController 5. 新建动作或BlendTree,设置参数 ...

  6. Grid布局如何设置动画效果

    CS代码 新增 GridLengthAnimation继承自AnimationTimeline public class GridLengthAnimation : AnimationTimeline ...

  7. 一起学android之设置ListView数据显示的动画效果(24)

    效果图: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaGFpX3FpbmdfeHVfa29uZw==/font/5a6L5L2T/fontsize/40 ...

  8. setAnimationStyle实现的popwindow显示消失的动画效果

    摘要 popwindow通过setAnimationStyle(int animationStyle)函数来设置动画效果 android:windowEnterAnimation表示进入窗口动画 an ...

  9. Qt动画效果展示(文艺IT男)

    该程序使用应用程序单窗口,主窗口继承于QMainWindow:主窗口有5个QToolButton部件(窗口底部的四个以及窗口中央的一个),单击窗口底部的QToolButton部件可以使窗口中央的那个Q ...

随机推荐

  1. [Angular] @ContentChildren and QueryList

    We have looked at @ContentChild in article(http://www.cnblogs.com/Answer1215/p/6414657.html). Now le ...

  2. (ubuntu 下)tensorflow 的安装及版本升级

    对于 CPU 版本 pip3 install –upgrade tensorflow 对于 GPU 版本: pip3 install –upgrade tensorflow-gpu [TensorFl ...

  3. WPF入门(三)->几何图形之线条(LineGeometry)

    原文:WPF入门(三)->几何图形之线条(LineGeometry) 前一章我们对wpf的xaml语言有了一定的了解,那么我们现在开始来学习如何使用wpf来画出几何图形. LineGeometr ...

  4. 【codeforces 791A】Bear and Big Brother

    [题目链接]:http://codeforces.com/contest/791/problem/A [题意] 给你两个数字a和b; a每次乘3,b每次乘2 问你什么时候a第一次大于b [题解] 傻逼 ...

  5. Codeforces C. Pattern 412 解决问题的方法

    这个问题是比较暴力的法律主体. 主要是检查每一个是否没有使用足够的?.假设优先使用其他的无论是什么字母,假设你一定不能使用?. 找一个有能力并给予所有的字符串匹配字符串,而且采用的最小?号码. 原标题 ...

  6. No_Sql总结

    NoSQL简介 NoSQL(NoSQL = Not Only SQL ),意即"不仅仅是SQL",是对不同于传统的关系型数据库的数据库管理系统的统称.在现代的计算系统上每天网络上都 ...

  7. ubuntu 在配置MySQL维修

    第一步 设备MySQL sudo apt-get install mysql-server 第二步骤 构造MySQL 2.1 vim /etc/mysql/my.cnf 到场bind-address ...

  8. HTML:描述语义

    一.HTML HTML:Hypertext Markup Launguage,超文本标记语言,是网页的就文件格式,用于描述网页语义. 二.HTML骨架 DTD手册:http://www.w3schoo ...

  9. Scala & IntelliJ IDEA环境搭建升级版:在JAVA中调用Scala的helloworld

    --------------------- 前言 --------------------- 项目关系,希望用Spark GraphX做数据分析及图像展示,但前提是得会spark:spark是基于sc ...

  10. [OpenGL]OpenGL坐标系和坐标变换

    OpenGL通过摄像机的模拟.要实现一个三维计算机图形重大转变,这是几何变换(模型转换-查看转型(两者统称为几何变换)).投影.作物转型.口变换等.同一时候,OpenGL还实现了矩阵堆栈等.理解掌握了 ...