创建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. C 语言 —— ! 和 ~(感叹号和波浪号)

    ~ 表示按位取反,是位运算符,运算对象是 2 进制. !表示逻辑非,是逻辑运算符,运算对象是真或假.最终的结果也是 0/1 !!:则表示取过一次非之后,再取一次: !!5 ⇒ 1

  2. Angular.js回想+学习笔记(1)【ng-app和ng-model】

    Angular.js中index.html简单结构: <!doctype html> <html ng-app> <head> <script src=&qu ...

  3. [经典面试题]k节点一组旋转链表

    [题目] 给出一个链表和一个数k,比方链表1→2→3→4→5→6.k=2,则翻转后2→1→4→3→6→5,若k=3,翻转后3→2→1→6→5→4,若k=4.翻转后4→3→2→1→5→6. 假设节点的数 ...

  4. 使用SecureCRT连接AWS的EC2

    如果使用CentOS等linux系统,直接使用ssh命令即可访问AWS上的Linux-EC2实例. $ ssh -i XXX.pem ec2-user@{IP/hostname} 在Windows系统 ...

  5. Java数据类型转换问题

    基本数据类型 整数型 byte --- 字节型 --- 1个字节 --- -27~27-1 -> -128~127 byte b1 = 25; byte b2 = 127; short --- ...

  6. hexo主题选择和配置

    之前用next主题,发现文章标题都是h2,不利于seo,想着通过改模板改成h1的,发现很繁琐.今天发现,通过下载指定版本的next后,标题自动是h1的. 参考网页https://notes.iissn ...

  7. Redux中reducer的翻译

    reduce有归纳,简化的意思,所以reducer可翻译成归并函数的意思,其实没必要翻译,大体知道就可以了.

  8. Hibernate——(6)延迟加载机制

    一.延迟加载机制的基本原理 当访问实体对象时,并不是立即到数据库中查找.而是在真正要使用实体对象的时候,才去数据库查询数据. 具备这样功能的方法 session.load(...) query.ite ...

  9. C-order/Fortran-order(Row-/Column-major order)

    1. row-major / column-major order 无论是行序优先还是列序优先,其实在计算机计算中,指的都是在线性空间(linear storage,如 RAM,也即连续内存存储 co ...

  10. Android app设置全屏模式

    Android中,为APP设置全屏模式,主要有如下几种方式: 在manifest中设置 在项目中找到AndroidManifest.xml配置文件,找到Activity所在的节点,添加theme. & ...