创建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. php如何实现万年历的开发(每日一课真是非常有效率)

    php如何实现万年历的开发(每日一课真是非常有效率) 一.总结 一句话总结: 1.判断每月有多少天: 通过data函数来判断,$days=date('t',$firstday); 2.判断每月的第一天 ...

  2. Method and apparatus for loading a segment register in a microprocessor capable of operating in multiple modes

    A microprocessor contains an address generation unit, including a segment block, for loading descrip ...

  3. js进阶 9-11 select选项框如何动态添加和删除元素

    js进阶 9-11 select选项框如何动态添加和删除元素 一.总结 一句话总结: 二.js进阶 9-11 select选项框如何动态添加和删除元素 1.案例说明 2.相关知识 Select 下拉列 ...

  4. Android中再按一次退出实现

    很多应用中都有一个在用户后退的时候显示"再按一次退出"的提醒,这个怎么实现呢?有两种方式 第一种方式(最常用) long waitTime = 2000; long touchTi ...

  5. python 爬取豆瓣的美剧

    pc版大概有500条记录,mobile大概是50部,只有热门的,所以少一点 url构造很简单,主要参数就是page_limit与page_start,每翻一页,start+=20即可,tag是&quo ...

  6. oracle的sql查询结果拼接

    oracle数据库中,使用wm_concat(column)函数,可以进行字段合并 oracle wm_concat(column)函数使我们经常会使用到的,下面就教您如何使用oracle wm_co ...

  7. lucene 7.x 排序

    一.创建索引 @Test public void indexCreate() throws IOException { //创建分词器 Analyzer analyzer = new Standard ...

  8. 买不起360随声wifi怎么办?这些都不是问题

    只需轻松一步,点击开启共享 软件下载地址:http://download.csdn.net/detail/lxq_xsyu/6384265 如果身边没有数据线怎么办?? 使用方法: 1.用手机连接Wi ...

  9. C# WPF 左侧菜单右侧内容布局效果实现

    原文:C# WPF 左侧菜单右侧内容布局效果实现 我们要做的效果是这样的,左侧是可折叠的菜单栏,右侧是内容区域,点击左侧的菜单项右侧内容区域则相应地切换. wpf实现的话,我的办法是用一个tabcon ...

  10. Extensible Access Control List Framework

    Methods, systems, and products for governing access to objects on a filesystem. In one general embod ...