底部弹出popWindow的动画
2015-06-30 20:13
267 查看
当我点击按钮的时候,主界面的下方会弹出popWindow.而且popwindow具有一定的动画效果.
主要的思路是:
设置其窗口的布局文件,出现的位置,弹出时的动画效果,还有控件的事件处理.
1 首先创建popWindow的布局文件:
2 创建popwindow的动画的xml文件:
1 隐藏时的动画效果:
2 出现时的动画效果:
3 创建样式,在style.xml文件中添加代码:
3 在MainActivity中,处理按钮的点击事件:
主要的思路是:
设置其窗口的布局文件,出现的位置,弹出时的动画效果,还有控件的事件处理.
1 首先创建popWindow的布局文件:
[code]<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="5dp" android:orientation="vertical" > <!-- 这里的linearLayout加android:background=""这个属性要谨慎,如果加了后,popwindow是不能半透明了的 --> <Button android:id="@+id/first" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="5dp" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:layout_marginTop="5dp" android:background="@color/red" android:text="第一个按钮" /> <Button android:id="@+id/second" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="5dp" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:background="@color/red" android:text="第二个按钮" /> <Button android:id="@+id/third" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="5dp" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:background="@color/red" android:text="第三个按钮" /> </LinearLayout>
2 创建popwindow的动画的xml文件:
1 隐藏时的动画效果:
[code]<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:duration="1000" android:fromYDelta="0" android:toYDelta="50%p" /> <alpha android:duration="1000" android:fromAlpha="1.0" android:toAlpha="0.0" /> </set>
2 出现时的动画效果:
[code]<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:duration="1000" android:fromYDelta="100%p" android:toYDelta="0" /> <alpha android:duration="1000" android:fromAlpha="0.0" android:toAlpha="1.0" /> </set>
3 创建样式,在style.xml文件中添加代码:
[code] <!-- 这个是加入的代码 --> <style name="mypopwindow_anim_style"> <item name="android:windowEnterAnimation">@anim/popshow_anim</item> <!-- 指定显示的动画xml --> <item name="android:windowExitAnimation">@anim/pophidden_anim</item> <!-- 指定消失的动画xml --> </style>
3 在MainActivity中,处理按钮的点击事件:
[code]public void show(View view){ Toast.makeText(this, "hhh",Toast.LENGTH_LONG).show(); LayoutInflater inflater=(LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); View v=inflater.inflate(R.layout.popwindow,null); PopupWindow window=new PopupWindow(v, WindowManager.LayoutParams.MATCH_PARENT,WindowManager.LayoutParams.WRAP_CONTENT); window.setFocusable(true); //设置背景 ColorDrawable dw = new ColorDrawable(0xb0000000); window.setBackgroundDrawable(dw); //设置动画 window.setAnimationStyle(R.style.mypopwindow_anim_style); //设置展现的位置 window.showAtLocation(this.findViewById(R.id.start), Gravity.BOTTOM,0,0); v.findViewById(R.id.first).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Toast.makeText(MainActivity.this,"第一个按钮被点击",Toast.LENGTH_LONG).show(); } }); window.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss() { // TODO Auto-generated method stub Toast.makeText(MainActivity.this,"消失",Toast.LENGTH_LONG).show(); } }); }
相关文章推荐
- Hadoop常见重要命令行操作及命令作用
- linux open()函数各参数说明
- [转载]应用 Valgrind 发现 Linux 程序的内存问题
- 配置squid 代理
- Linux 千万不要执行的10个命令
- Linux基础指令大全
- Linux 下 signal 机制
- Linux服务器管理: 系统的定时任务crond
- 非常有趣linux图形及动画显示-菜鸟提升兴趣必看!
- 非常有趣linux图形及动画显示-菜鸟提升兴趣必看!
- 非常有趣linux图形及动画显示-菜鸟提升兴趣必看!
- 非常有趣linux图形及动画显示-菜鸟提升兴趣必看!
- linux命令:crontab命令(转)
- mediawiki中全局变量$wgLogo用于设置网站的Logo
- Linux命令随记
- IT架构之IT架构标准——思维导图
- MOS X 下Apache服务器配置,及日志读取
- Web前端体系架构
- linux定时运行命令脚本——crontab
- Tomcat源码学习——第2章