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, ,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[];
btns[]=view.findViewById(R.id.btn_0);
btns[]=view.findViewById(R.id.btn_1);
btns[]=view.findViewById(R.id.btn_2);
btns[].setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) {
// TODO Auto-generated method stub
//doSomething
}
});
btns[].setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) {
// TODO Auto-generated method stub
//doSomething
}
});
btns[].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, , );
}
}
public Bitmap setRotate(int resId) {
Matrix mFgMatrix = new Matrix();
Bitmap mFgBitmap = BitmapFactory.decodeResource(getResources(), resId);
mFgMatrix.setRotate(180f);
return mFgBitmap=Bitmap.createBitmap(mFgBitmap, , ,
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=""
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=""
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=""
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="" />
<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="" android:delay="" />
<alpha android:interpolator="@android:anim/linear_interpolator"
android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="" />
</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="" />
<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="" android:delay="" />
<alpha android:interpolator="@android:anim/linear_interpolator"
android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="" />
</set>

最后用下面的 XML 封装:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="PopupAnimation" parent="android:Animation"
mce_bogus="">
<item name="android:windowEnterAnimation">@anim/anim_dialog_show</item>
<item name="android:windowExitAnimation">@anim/anim_dialog_hide</item>
</style>
</resources>

DraweRoll.rar

 

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

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

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

  2. 自定义PopupWindow动画效果

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

  3. Android自定义类似ProgressDialog效果的Dialog

    Android自定义类似ProgressDialog效果的Dialog. 方法如下: 1.首先准备两张自己要定义成哪样子的效果的图片和背景图片(也可以不要背景). 如我要的效果: 2.定义loadin ...

  4. Android 自定义波浪动画 --"让进度浪起来~"

    原文链接:http://www.jianshu.com/p/0e25a10cb9f5 一款效果不错的动画,实现也挺简单的,推荐阅读学习~ -- 由 傻小孩b 分享 waveview <Andro ...

  5. Android 自定义帧动画

    Android 自定义帧动画 Android L : Android Studio 帧动画 和gif图片类似,顺序播放准本好的图片文件:图片资源在xml文件中配置好 将图片按照预定的顺序一张张切换,即 ...

  6. Android中的动画效果

    动画的种类 透明动画alphaAnimation 在代码中配置动画: findViewById(R.id.btnAnimMe).setOnClickListener(new View.OnClickL ...

  7. Android自定义窗口动画

    第一步,设置出现和消失的xml 1.在res/anim下创建enter_anim.xml,设置窗口出现的动画 <?xml version="1.0" encoding=&qu ...

  8. android Activity切换动画效果

    为Activity设置左右进出的效果,能够通过在Mainfest.xml文件里设置主题的方式来实现.还能够使用java代码. 一.设置样式 先看看实现动画的样式: <style name=&qu ...

  9. 自定义UIView动画效果

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

随机推荐

  1. JS 输出对象的属性以及方法[转载]

    <script>var obj  = {attribute:1,method:function() {alert("我是函数");}}for (var i in obj ...

  2. Mac Outlook数据文件的位置

    ****/Documents/Microsoft User Data/Office 2011 Identities/Main Identity 在这里 如果是中文版的,在这里: /Users/×××× ...

  3. 什么是Elasticsearch

    一个采用Restfull API 标准的高扩展性和高可用性的实时数据分析的全文搜索工具 Elasticsearch 涉及到的一些概念: 1.Node(节点): 单个的装有Elasticsearch服务 ...

  4. C语言的本质(38)——makefile之变量

    我们详细看看Makefile中关于变量的语法规则.先看一个简单的例子: foo = $(bar) bar = Huh? all: @echo$(foo) 我们执行make将会打出Huh?.当make读 ...

  5. UVA_Digit Puzzle UVA 12107

    If you hide some digits in an integer equation, you create a digit puzzle. The figure below shows tw ...

  6. 求解答,Android源码编译时怎样添加第三方jar包

    各位大神好,遇到的问题如标题. 我用Eclipse写了一个android工程,但是这个工程需要到SDK的隐藏类,所有想在源码下编译,但是每次mm之后,都会出现错误,提示是找不到对应的类. 我需要加入的 ...

  7. Swift继承的用法

    一个类可以继承另一个类的方法,属性和其它特性.当一个类继承其它类,继承类叫子类,被继承类叫超类(或父类).在Swift中,继承是区分「类」与其它类型的一个基本特征. 在Swift中,类可以调用和访问超 ...

  8. CSS入门教程——定位(positon)

    CSS入门教程——定位(positon) CSS定位在网页布局中是起着决定性作用.   定位 CSS的定位功能是很强大的,利用它你可以做出各种各样的网页布局.本节就介绍一些CSS常用的定位语句. 1. ...

  9. centos 6 编译安装httpd-2.4

    centos6 yum安装的apr版本已经不适用httpd-2.4版本了.所以,需要源码编译apr以及apr-util 1. 下载源码: cd /usr/local/src/ wget http:// ...

  10. 80端口被NT kernel & System 占用pid= 4的解决方法

    引用http://www.2cto.com/os/201111/111269.html的方法.亲测可用 该进程是Http.sys.它是http API的驱动组件,Http栈服务器.如果该端口被Http ...