1. public class RollActivity extends Activity {
  2. private View view;
  3. private Button btn;
  4. private PopupWindow mPopupWindow;
  5. private View[] btns;
  6. /** Called when the activity is first created. */
  7. @Override
  8. public void onCreate(Bundle savedInstanceState) {
  9. super.onCreate(savedInstanceState);
  10. setContentView(R.layout.main);
  11. //      LinearLayout layout=(LinearLayout) view.findViewById(R.id.layout_main);
  12. //      //设置背景图片旋转180
  13. //      Bitmap mBitmap=setRotate(R.drawable.bg_kuang);
  14. //      BitmapDrawable drawable=new BitmapDrawable(mBitmap);
  15. //      layout.setBackgroundDrawable(drawable);
  16. btn=(Button) this.findViewById(R.id.btn);
  17. btn.setOnClickListener(new OnClickListener(){
  18. @Override
  19. public void onClick(View v) {
  20. // TODO Auto-generated method stub
  21. showPopupWindow(btn);
  22. }
  23. });
  24. initPopupWindow(R.layout.popwindow);
  25. }
  26. private void initPopupWindow(int resId){
  27. LayoutInflater mLayoutInflater = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
  28. view = mLayoutInflater.inflate(resId, null);
  29. mPopupWindow = new PopupWindow(view, 400,LayoutParams.WRAP_CONTENT);
  30. //      mPopupWindow.setBackgroundDrawable(new BitmapDrawable());//必须设置background才能消失
  31. mPopupWindow.setBackgroundDrawable(getResources().getDrawable(R.drawable.bg_frame));
  32. mPopupWindow.setOutsideTouchable(true);
  33. //自定义动画
  34. //      mPopupWindow.setAnimationStyle(R.style.PopupAnimation);
  35. //使用系统动画
  36. mPopupWindow.setAnimationStyle(android.R.style.Animation_Dialog);
  37. mPopupWindow.update();
  38. mPopupWindow.setTouchable(true);
  39. mPopupWindow.setFocusable(true);
  40. btns=new View[3];
  41. btns[0]=view.findViewById(R.id.btn_0);
  42. btns[1]=view.findViewById(R.id.btn_1);
  43. btns[2]=view.findViewById(R.id.btn_2);
  44. btns[0].setOnClickListener(new OnClickListener() {
  45. @Override
  46. public void onClick(View v) {
  47. // TODO Auto-generated method stub
  48. //doSomething
  49. }
  50. });
  51. btns[1].setOnClickListener(new OnClickListener() {
  52. @Override
  53. public void onClick(View v) {
  54. // TODO Auto-generated method stub
  55. //doSomething
  56. }
  57. });
  58. btns[2].setOnClickListener(new OnClickListener() {
  59. @Override
  60. public void onClick(View v) {
  61. // TODO Auto-generated method stub
  62. //doSomething
  63. }
  64. });
  65. }
  66. private void showPopupWindow(View view) {
  67. if(!mPopupWindow.isShowing()){
  68. //          mPopupWindow.showAsDropDown(view,0,0);
  69. mPopupWindow.showAtLocation(view, Gravity.CENTER, 0, 0);
  70. }
  71. }
  72. public Bitmap setRotate(int resId) {
  73. Matrix mFgMatrix = new Matrix();
  74. Bitmap mFgBitmap = BitmapFactory.decodeResource(getResources(), resId);
  75. mFgMatrix.setRotate(180f);
  76. return mFgBitmap=Bitmap.createBitmap(mFgBitmap, 0, 0,
  77. mFgBitmap.getWidth(), mFgBitmap.getHeight(), mFgMatrix, true);
  78. }
  79. }

PopupWindow的布局popwindow.xml 
注意3个LinearLayout里必须设置clickable和background,这样当点击上去的时候才会有点击效果。 
android:clickable="true" 
android:background="@drawable/state_btn_pressed"

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout
  3. xmlns:android="http://schemas.android.com/apk/res/android"
  4. android:layout_width="fill_parent"
  5. android:layout_height="wrap_content"
  6. android:orientation="horizontal"
  7. android:id="@+id/layout_main"
  8. >
  9. <LinearLayout android:layout_width="fill_parent"
  10. android:layout_height="wrap_content"
  11. android:orientation="vertical"
  12. android:gravity="center_horizontal"
  13. android:clickable="true"
  14. android:background="@drawable/state_btn_pressed"
  15. android:layout_weight="1"
  16. android:id="@+id/btn_0"
  17. >
  18. <ImageView android:layout_width="wrap_content"
  19. android:layout_height="wrap_content"
  20. android:scaleType="fitCenter"
  21. android:src="@drawable/ic_call"
  22. >
  23. </ImageView>
  24. <TextView android:layout_width="wrap_content"
  25. android:layout_height="wrap_content"
  26. android:textColor="#000000"
  27. android:textSize="18px"
  28. android:text="电话">
  29. </TextView>
  30. </LinearLayout>
  31. <LinearLayout android:layout_width="fill_parent"
  32. android:layout_height="wrap_content"
  33. android:orientation="vertical"
  34. android:gravity="center_horizontal"
  35. android:clickable="true"
  36. android:background="@drawable/state_btn_pressed"
  37. android:layout_weight="1"
  38. android:id="@+id/btn_1"
  39. >
  40. <ImageView android:layout_width="wrap_content"
  41. android:layout_height="wrap_content"
  42. android:scaleType="fitCenter"
  43. android:src="@drawable/ic_home"
  44. >
  45. </ImageView>
  46. <TextView android:layout_width="wrap_content"
  47. android:layout_height="wrap_content"
  48. android:textColor="#000"
  49. android:textSize="18px"
  50. android:text="空间">
  51. </TextView>
  52. </LinearLayout>
  53. <LinearLayout android:layout_width="fill_parent"
  54. android:layout_height="wrap_content"
  55. android:orientation="vertical"
  56. android:gravity="center_horizontal"
  57. android:clickable="true"
  58. android:background="@drawable/state_btn_pressed"
  59. android:layout_weight="1"
  60. android:id="@+id/btn_2"
  61. >
  62. <ImageView android:layout_width="wrap_content"
  63. android:layout_height="wrap_content"
  64. android:scaleType="fitCenter"
  65. android:src="@drawable/ic_sms"
  66. >
  67. </ImageView>
  68. <TextView android:layout_width="wrap_content"
  69. android:layout_height="wrap_content"
  70. android:textColor="#000"
  71. android:textSize="18px"
  72. android:text="短信"
  73. >
  74. </TextView>
  75. </LinearLayout>
  76. </LinearLayout>

state_btn_pressed.xml,点击的效果:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <selector xmlns:android="http://schemas.android.com/apk/res/android">
  3. <item android:state_pressed="true"
  4. android:drawable="@drawable/bg_btn_pressed"
  5. android:padding="0dp"/>
  6. </selector>

Android 模仿迅雷的 PopupWindow 出现/消失动画 
出现:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <set xmlns:android="http://schemas.android.com/apk/res/android">
  3. <scale android:fromXScale="0.6" android:toXScale="1.1"
  4. android:fromYScale="0.6" android:toYScale="1.1" android:pivotX="50%"
  5. android:pivotY="50%" android:duration="200" />
  6. <scale android:fromXScale="1.0" android:toXScale="0.91"
  7. android:fromYScale="1.0" android:toYScale="0.91" android:pivotX="50%"
  8. android:pivotY="50%" android:duration="400" android:delay="200" />
  9. <alpha android:interpolator="@android:anim/linear_interpolator"
  10. android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="400" />
  11. </set>

消失:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <set xmlns:android="http://schemas.android.com/apk/res/android">
  3. <scale android:fromXScale="1.0" android:toXScale="1.25"
  4. android:fromYScale="1.0" android:toYScale="1.25" android:pivotX="50%"
  5. android:pivotY="50%" android:duration="200" />
  6. <scale android:fromXScale="1.0" android:toXScale="0.48"
  7. android:fromYScale="1.0" android:toYScale="0.48" android:pivotX="50%"
  8. android:pivotY="50%" android:duration="400" android:delay="200" />
  9. <alpha android:interpolator="@android:anim/linear_interpolator"
  10. android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="400" />
  11. </set>

最后用下面的 XML 封装:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <resources>
  3. <style name="PopupAnimation" parent="android:Animation"
  4. mce_bogus="1">
  5. <item name="android:windowEnterAnimation">@anim/anim_dialog_show</item>
  6. <item name="android:windowExitAnimation">@anim/anim_dialog_hide</item>
  7. </style>
  8. </resources>

自定义PopupWindow动画效果的更多相关文章

  1. Android 自定义PopupWindow动画效果

    public class RollActivity extends Activity { private View view; private Button btn; private PopupWin ...

  2. 自定义UIView动画效果

    最普通动画: //开始动画 [UIView beginAnimations:nil context:nil]; //设定动画持续时间 [UIView setAnimationDuration:]; / ...

  3. 实例源码--Android自定义Gallery动画效果

    相关文档与源码: 下载源码   技术要点: 1.自定义控件的使用 2.Gallery控件的使用实例 3.详细的源码注释 ...... 详细介绍: 1.自定义控件的使用 本套源码通过自定义控件的方式,继 ...

  4. Android动画效果之自定义ViewGroup添加布局动画

    前言: 前面几篇文章介绍了补间动画.逐帧动画.属性动画,大部分都是针对View来实现的动画,那么该如何为了一个ViewGroup添加动画呢?今天结合自定义ViewGroup来学习一下布局动画.本文将通 ...

  5. CSS--使用Animate.css制作动画效果

    一 使用Animate.css动画 // 通过@import引入外部CSS资源; // 引入线上图片及JS文件; // 通过更改CSS类名生成不同类型的CSS3动画;   <!DOCTYPE h ...

  6. iOS学习笔记-自定义过渡动画

    代码地址如下:http://www.demodashi.com/demo/11678.html 这篇笔记翻译自raywenderlick网站的过渡动画的一篇文章,原文用的swift,由于考虑到swif ...

  7. web前端学习(三)css学习笔记部分(8)-- SVN的介绍和应用、CSS动画效果、CSS3布局属性全接触

    15.SVN的介绍和应用 15.1.SVN的介绍和应用课程概要 将代码进行集中管理,有版本号的进行迭代,方便集体工作的build流程 15.2.SVN的介绍 SVN是Subversion的简称,是一个 ...

  8. popupwindow的基本使用以及基本动画效果

    1.创建一个popupwindow view的布局文件自己写一个就好了,这里就不说了 View view= LayoutInflater.from(context).inflate(R.layout. ...

  9. android标题栏上面弹出提示框(二) PopupWindow实现,带动画效果

    需求:上次用TextView写了一个从标题栏下面弹出的提示框.android标题栏下面弹出提示框(一) TextView实现,带动画效果,  总在找事情做的产品经理又提出了奇葩的需求.之前在通知栏显示 ...

随机推荐

  1. SVN库迁移整理方法总结

    有时候需要从一台机器迁移svn存储库到另外一台机器,如果数据量非常大的话,没有好的方法是很不方便的,其实迁移svn跟迁移mysql差不多,也有导出导入的方案 以下是subversion官方推荐的备份方 ...

  2. oracle遍历游标

    1,while循环 declare v_tname ); cursor c_tname is select a.TABLE_NAME from user_tables a where a.TABLES ...

  3. rtsp转发服务器设计

    做一个设备实时监控.需求是这样的,一个用户有多个设备(android系统,支持摄像头),设备分布在家中或者其它地方:用户可以远程通过终端(手机.pc.ipad,etc...)管理操纵这些设备(包括实时 ...

  4. iOS用心学 UI基础之UIView

    一.引入UI 在实际开发中,基本的流程大致如下图所示: UI(User Interface)作为最基本的要点,也是非常重要的一部分,UI界面的美观直接决定着着用户的体验,苹果官方给开发中提供了非常强大 ...

  5. 在 ASP.NET 网页中不经过回发而实现客户端回调

    一.使用回调函数的好处 在 ASP.NET 网页的默认模型中,用户会与页交互,单击按钮或执行导致回发的一些其他操作.此时将重新创建页及其控件,并在服务器上运行页代码,且新版本的页被呈现到浏览器.但是, ...

  6. sql server使用说明

    什么是sql server? SqlServer是微软的一款数据库系统产品. 是DBMS中的一种. 当每一个数据库安装到每一台电脑后,都会与计算机名称(有的是IP地址)关联.因为服务器用途的电脑不能经 ...

  7. querySelector选择器

    querySelector选择器可以通过document和element来调用他们 用来代替getElementById var body=document.querySelector("b ...

  8. Laravel5中集成Jasig cas统一认证系统

    CAS : CAS(Central Authentication Service)是一款不错的针对 Web 应用的单点登录框架,这里介绍下我刚在laravel5上搭建成功的cas.提前准备工作:可运行 ...

  9. php 产生不重复的随机数

    $arr=array();//创建数组 while(count($arr)<10){ $a = mt_rand(1000,9999);//产生随机数 if(!in_array($a,$arr)) ...

  10. Java内部类和外部类的通信探索

    1.内部类访问外部类的成员和方法 在内部类中,可以无障碍地访问外部类的所有成员和方法. 在下面的实验代码中,可以看到,内部类sl可以访问外部类的私有成员:sz 和 cur. 同时可以访问私有方法:pr ...