自定义PopupWindow动画效果
- public class RollActivity extends Activity {
- private View view;
- private Button btn;
- private PopupWindow mPopupWindow;
- private View[] btns;
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- // LinearLayout layout=(LinearLayout) view.findViewById(R.id.layout_main);
- // //设置背景图片旋转180
- // Bitmap mBitmap=setRotate(R.drawable.bg_kuang);
- // BitmapDrawable drawable=new BitmapDrawable(mBitmap);
- // layout.setBackgroundDrawable(drawable);
- btn=(Button) this.findViewById(R.id.btn);
- btn.setOnClickListener(new OnClickListener(){
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- showPopupWindow(btn);
- }
- });
- initPopupWindow(R.layout.popwindow);
- }
- private void initPopupWindow(int resId){
- LayoutInflater mLayoutInflater = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
- view = mLayoutInflater.inflate(resId, null);
- mPopupWindow = new PopupWindow(view, 400,LayoutParams.WRAP_CONTENT);
- // mPopupWindow.setBackgroundDrawable(new BitmapDrawable());//必须设置background才能消失
- mPopupWindow.setBackgroundDrawable(getResources().getDrawable(R.drawable.bg_frame));
- mPopupWindow.setOutsideTouchable(true);
- //自定义动画
- // mPopupWindow.setAnimationStyle(R.style.PopupAnimation);
- //使用系统动画
- mPopupWindow.setAnimationStyle(android.R.style.Animation_Dialog);
- mPopupWindow.update();
- mPopupWindow.setTouchable(true);
- mPopupWindow.setFocusable(true);
- btns=new View[3];
- btns[0]=view.findViewById(R.id.btn_0);
- btns[1]=view.findViewById(R.id.btn_1);
- btns[2]=view.findViewById(R.id.btn_2);
- btns[0].setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- //doSomething
- }
- });
- btns[1].setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- //doSomething
- }
- });
- btns[2].setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- //doSomething
- }
- });
- }
- private void showPopupWindow(View view) {
- if(!mPopupWindow.isShowing()){
- // mPopupWindow.showAsDropDown(view,0,0);
- mPopupWindow.showAtLocation(view, Gravity.CENTER, 0, 0);
- }
- }
- public Bitmap setRotate(int resId) {
- Matrix mFgMatrix = new Matrix();
- Bitmap mFgBitmap = BitmapFactory.decodeResource(getResources(), resId);
- mFgMatrix.setRotate(180f);
- return mFgBitmap=Bitmap.createBitmap(mFgBitmap, 0, 0,
- mFgBitmap.getWidth(), mFgBitmap.getHeight(), mFgMatrix, true);
- }
- }
PopupWindow的布局popwindow.xml
注意3个LinearLayout里必须设置clickable和background,这样当点击上去的时候才会有点击效果。
android:clickable="true"
android:background="@drawable/state_btn_pressed"
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal"
- android:id="@+id/layout_main"
- >
- <LinearLayout android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical"
- android:gravity="center_horizontal"
- android:clickable="true"
- android:background="@drawable/state_btn_pressed"
- android:layout_weight="1"
- android:id="@+id/btn_0"
- >
- <ImageView android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:scaleType="fitCenter"
- android:src="@drawable/ic_call"
- >
- </ImageView>
- <TextView android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:textColor="#000000"
- android:textSize="18px"
- android:text="电话">
- </TextView>
- </LinearLayout>
- <LinearLayout android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical"
- android:gravity="center_horizontal"
- android:clickable="true"
- android:background="@drawable/state_btn_pressed"
- android:layout_weight="1"
- android:id="@+id/btn_1"
- >
- <ImageView android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:scaleType="fitCenter"
- android:src="@drawable/ic_home"
- >
- </ImageView>
- <TextView android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:textColor="#000"
- android:textSize="18px"
- android:text="空间">
- </TextView>
- </LinearLayout>
- <LinearLayout android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical"
- android:gravity="center_horizontal"
- android:clickable="true"
- android:background="@drawable/state_btn_pressed"
- android:layout_weight="1"
- android:id="@+id/btn_2"
- >
- <ImageView android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:scaleType="fitCenter"
- android:src="@drawable/ic_sms"
- >
- </ImageView>
- <TextView android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:textColor="#000"
- android:textSize="18px"
- android:text="短信"
- >
- </TextView>
- </LinearLayout>
- </LinearLayout>
state_btn_pressed.xml,点击的效果:
- <?xml version="1.0" encoding="utf-8"?>
- <selector xmlns:android="http://schemas.android.com/apk/res/android">
- <item android:state_pressed="true"
- android:drawable="@drawable/bg_btn_pressed"
- android:padding="0dp"/>
- </selector>
Android 模仿迅雷的 PopupWindow 出现/消失动画
出现:
- <?xml version="1.0" encoding="utf-8"?>
- <set xmlns:android="http://schemas.android.com/apk/res/android">
- <scale android:fromXScale="0.6" android:toXScale="1.1"
- android:fromYScale="0.6" android:toYScale="1.1" android:pivotX="50%"
- android:pivotY="50%" android:duration="200" />
- <scale android:fromXScale="1.0" android:toXScale="0.91"
- android:fromYScale="1.0" android:toYScale="0.91" android:pivotX="50%"
- android:pivotY="50%" android:duration="400" android:delay="200" />
- <alpha android:interpolator="@android:anim/linear_interpolator"
- android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="400" />
- </set>
消失:
- <?xml version="1.0" encoding="utf-8"?>
- <set xmlns:android="http://schemas.android.com/apk/res/android">
- <scale android:fromXScale="1.0" android:toXScale="1.25"
- android:fromYScale="1.0" android:toYScale="1.25" android:pivotX="50%"
- android:pivotY="50%" android:duration="200" />
- <scale android:fromXScale="1.0" android:toXScale="0.48"
- android:fromYScale="1.0" android:toYScale="0.48" android:pivotX="50%"
- android:pivotY="50%" android:duration="400" android:delay="200" />
- <alpha android:interpolator="@android:anim/linear_interpolator"
- android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="400" />
- </set>
最后用下面的 XML 封装:
- <?xml version="1.0" encoding="utf-8"?>
- <resources>
- <style name="PopupAnimation" parent="android:Animation"
- mce_bogus="1">
- <item name="android:windowEnterAnimation">@anim/anim_dialog_show</item>
- <item name="android:windowExitAnimation">@anim/anim_dialog_hide</item>
- </style>
- </resources>
- DraweRoll.rar (111 KB)
- 下载次数: 806
自定义PopupWindow动画效果的更多相关文章
- Android 自定义PopupWindow动画效果
public class RollActivity extends Activity { private View view; private Button btn; private PopupWin ...
- 自定义UIView动画效果
最普通动画: //开始动画 [UIView beginAnimations:nil context:nil]; //设定动画持续时间 [UIView setAnimationDuration:]; / ...
- 实例源码--Android自定义Gallery动画效果
相关文档与源码: 下载源码 技术要点: 1.自定义控件的使用 2.Gallery控件的使用实例 3.详细的源码注释 ...... 详细介绍: 1.自定义控件的使用 本套源码通过自定义控件的方式,继 ...
- Android动画效果之自定义ViewGroup添加布局动画
前言: 前面几篇文章介绍了补间动画.逐帧动画.属性动画,大部分都是针对View来实现的动画,那么该如何为了一个ViewGroup添加动画呢?今天结合自定义ViewGroup来学习一下布局动画.本文将通 ...
- CSS--使用Animate.css制作动画效果
一 使用Animate.css动画 // 通过@import引入外部CSS资源; // 引入线上图片及JS文件; // 通过更改CSS类名生成不同类型的CSS3动画; <!DOCTYPE h ...
- iOS学习笔记-自定义过渡动画
代码地址如下:http://www.demodashi.com/demo/11678.html 这篇笔记翻译自raywenderlick网站的过渡动画的一篇文章,原文用的swift,由于考虑到swif ...
- web前端学习(三)css学习笔记部分(8)-- SVN的介绍和应用、CSS动画效果、CSS3布局属性全接触
15.SVN的介绍和应用 15.1.SVN的介绍和应用课程概要 将代码进行集中管理,有版本号的进行迭代,方便集体工作的build流程 15.2.SVN的介绍 SVN是Subversion的简称,是一个 ...
- popupwindow的基本使用以及基本动画效果
1.创建一个popupwindow view的布局文件自己写一个就好了,这里就不说了 View view= LayoutInflater.from(context).inflate(R.layout. ...
- android标题栏上面弹出提示框(二) PopupWindow实现,带动画效果
需求:上次用TextView写了一个从标题栏下面弹出的提示框.android标题栏下面弹出提示框(一) TextView实现,带动画效果, 总在找事情做的产品经理又提出了奇葩的需求.之前在通知栏显示 ...
随机推荐
- 定义Foo() 函数,弹出对话框提示当前选中的是第几个单选框
function foo(){ var ele = document.getElementsByName("radioElement"); for(var i = 0;i<e ...
- Swift中简单的单例设计
import Foundation class Test: NSObject { // 提供单例实例 static let shareInstance = Test() // 私有化构造方法 over ...
- nodejs概论
我将在此写下自己读<Node.js开发指南>一书的笔记,以便于以后的学习. 一.什么是node.js Node.js 是一个让 JavaScript 运行在浏览器之外的平台. Node.j ...
- 汇编test和cmp区别
来自http://tunps.com/assembly-test-and-cmp 看过破解教程,都知道test,cmp是比较关键,可是我一直不清楚它们究竟是怎么比较的,最后下决心找了很多资料,和大家一 ...
- EcStore操作笔记
1.去掉首页里面代码: <meta http-equiv="content-type" content="text/html; charset=utf-8" ...
- mysql版本问题sql_mode=only_full_group_by
set @@sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_ ...
- sudo gedit xx warning
When I sue command "sudo gedit xx", it appeas several warning: gedit:): IBUS-WARNING **: T ...
- Android onActivityResult 设置requestCode 返回的code不对
今天在项目里用到 Intent intent=new Intent(getActivity(), Test.class);startActivityForResult(intent, 1); onAc ...
- 找到 OSChina 早上 8 点钟容易宕机的原因 ?
最近一段时间,OSChina 网站在早上 8 点出头的时候很容易因为数据库连接池爆满而导致网站宕机.表现的情况是数据库处理大量的查询,堆积大量并发连接,导致无法再连接到数据库,执行一个简单的查询速度也 ...
- sigaction 用法实例
sigaction函数的功能是检查或修改与指定信号相关联的处理动作(可同时两种操作). 他是POSIX的信号接口,而signal()是标准C的信号接口(如果程序必须在非POSIX系统上运行,那么就应该 ...