PopUpWindow显示在某个View之上,同时使用动画
来源:互联网 发布:淘宝搜索宝贝显示地址 编辑:程序博客网 时间:2024/05/01 13:38
最近在写类似于美团的底部弹出购物车使用popupWindow来实现。
先讲解动画:在res/下新建一个文件夹anim,进而anim下新建两个xml文件,如图所示:
其中,pophidden_anim的代码如下
<?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>
popshow_anim的代码如下
<?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>
然后在values/styles.xml加入以下代码,变成这个样子,上面的那些是自带的
<resources> <!-- Base application theme, dependent on API level. This theme is replaced by AppBaseTheme from res/values-vXX/styles.xml on newer devices. --> <style name="AppBaseTheme" parent="android:Theme.Light"> <!-- Theme customizations available in newer API levels can go in res/values-vXX/styles.xml, while customizations related to backward-compatibility can go here. --> </style> <!-- Application theme. --> <style name="AppTheme" parent="AppBaseTheme"> <!-- All customizations that are NOT specific to a particular API-level can go here. --> </style> <!-- 这个是加入的代码 --> <style name="mypopwindow_anim_style"> <item name="android:windowEnterAnimation">@anim/popshow_anim</item> <!-- 指定显示的动画xml --> <item name="android:windowExitAnimation">@anim/pophidden_anim</item> <!-- 指定消失的动画xml --> </style></resources>代码中popupWindow使用:
popupWindow.setAnimationStyle(R.style.vegetable_pop);加载
刚开始在自定义View中要获取popUpWindow的高度一直不成功,最后修改如下
public class VegetableCarsWindow { private LayoutInflater inflater; private Activity context; private PopupWindow popupWindow; private View contentView; //显示的视图 public VegetableCarsWindow(Activity context){ this.context=context; inflater=context.getLayoutInflater(); contentView=inflater.inflate(R.layout.vegetable_popwindow, null); initView(); } public void initView(){ popupWindow=new PopupWindow(contentView, ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.WRAP_CONTENT); popupWindow.setFocusable(true); popupWindow.setOutsideTouchable(true); popupWindow.setBackgroundDrawable(new BitmapDrawable()); popupWindow.setAnimationStyle(R.style.vegetable_pop); popupWindow.setFocusable(true); contentView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); } public void setShow(View view){ int[] location = new int[2]; view.getLocationOnScreen(location); popupWindow.showAtLocation(view, Gravity.TOP, 0, location[1]-contentView.getMeasuredHeight()); //显示 }}红色部分是关键
0 0
- PopUpWindow显示在某个View之上,同时使用动画
- Android PopupWindow在控制之上显示
- 让PopupWindow显示在Dialog之上
- iOS: 在键盘之上显示一个 View
- Android 如何让某个view悬浮在其他界面之上?
- 如何让某个view悬浮在其他界面之上?
- PopupWindow显示在某个控件上方
- PopupWindow显示在某个控件上方
- PopupWindow显示在某个控件上方
- FloatingView 可以让 View 在别的 View 之上执行非常酷的漂浮动画
- Android在指定View的下方显示PopupWindow
- MediaController显示在VideoView之上
- 9/6使某个view显示在视图最上面
- 【android】让popupwindow显示在view的上方并与该view水平居中对齐
- 【android】让popupwindow显示在view的上方并与该view水平居中对齐
- 让popupwindow显示在view的上方并与该view水平居中对齐
- 让popupwindow显示在view的上方并与该view水平居中对齐
- popupWindow (弹出窗口)点击某个按钮时,在旁边显示其他按钮。
- lucene index 锁
- spring-data-redis用配置类连接时,抛异常Cannot get Jedis connection; nested exception is java.lang.NullPointerEx
- 74.深拷贝和完全拷贝对比的探究
- 回文字符串
- 关于Quaternion
- PopUpWindow显示在某个View之上,同时使用动画
- 前端工作总结
- 实现三列布局
- c++实验2
- Visual Studio 2013安装提示"此版本的Visual Studio需要安装了更新版本的windows的计算机"解决
- 算法竞赛前 准备文档
- 自己用python写的性能专项小脚本原理和使用
- 安卓简单手电筒开发
- window compile bitcoin