专业网站建设品牌,十四年专业建站经验,服务6000+客户--广州京杭网络
免费热线:400-683-0016      微信咨询  |  联系我们

popwindow设置了动画_CSS学习

当前位置:网站建设 > 技术支持
资料来源:网络整理       时间:2023/3/4 5:23:01       共计:3598 浏览

popwindow设置了动画?

封装:

/**

* 封装了显示Popupwindow的方法.* @author ansen* @create time 2015-10-27*/public class Util implements AnimationEndCallback{ private PopupWindow reportVideoPopwindow; public void showTips(Activity activity){ int translateHeight=(int) dip2px(activity,52); View parent = ((ViewGroup) activity.findViewById(android.R.id.content)).getChildAt(0); View popView = LayoutInflater.from(activity).inflate(R.layout.activity_popupwindow_tips, null); int statusBar=getStatusBarHeight(activity); reportVideoPopwindow = new PopupWindow(popView,LayoutParams.MATCH_PARENT,translateHeight*2); reportVideoPopwindow.showAtLocation(parent,Gravity.TOP, 0, 0); TipRelativeLayout tvTips=(TipRelativeLayout) popView.findViewById(R.id.rl_tips); tvTips.setTitleHeight(statusBar);//移动状态栏的高度 tvTips.setAnimationEnd(this);//设置动画结束监听函数 tvTips.showTips();//显示提示RelativeLayout,移动动画. } public int getStatusBarHeight(Context context) { int result = 0; int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android"); if (resourceId > 0) { result = context.getResources().getDimensionPixelSize(resourceId); } return result; } private float dip2px(Context context, float dpValue) { final float scale = context.getResources().getDisplayMetrics().density; float result = dpValue * scale + 0.5f; return result; } @Override public void onAnimationEnd() { reportVideoPopwindow.dismiss();//动画结束,隐藏popupwindow }}自定义RelativeLayout 显示提示信息,显示时有动画效果(从上面弹出,然后改变透明度慢慢隐藏public class TipRelativeLayout extends RelativeLayout{ private static final int START_TIME=400;//动画显示时间 private static final int END_TIME=400;//动画移出时间 private static final int SHOW_TIME=1000;//动画显示时间 private AnimationEndCallback animationEnd; private int titleHeight=100;//标题栏默认的高度设置成100 public TipRelativeLayout(Context context) { super(context); } public TipRelativeLayout(Context context, AttributeSet paramAttributeSet) { super(context, paramAttributeSet); } public TipRelativeLayout(Context context, AttributeSet paramAttributeSet,int paramInt) { super(context, paramAttributeSet, paramInt); } public void showTips(){ setVisibility(View.VISIBLE); //向下移动动画 TranslateAnimation downTranslateAnimation=new TranslateAnimation(0,0,0,titleHeight); downTranslateAnimation.setDuration(START_TIME); downTranslateAnimation.setFillAfter(true); startAnimation(downTranslateAnimation); //动画监听 downTranslateAnimation.setAnimationListener(new AnimationListener() { @Override public void onAnimationStart(Animation animation) {} @Override public void onAnimationEnd(Animation animation){//向下移动动画结束 topTranslateAnimation(); } @Override public void onAnimationRepeat(Animation animation) {} }); } private void topTranslateAnimation(){ new Handler().postDelayed(new Runnable() {//延时1秒之后再向上移动 @Override public void run(){ //向上移动动画 TranslateAnimation topTranslateAnimation=new TranslateAnimation(0,0,titleHeight,0); topTranslateAnimation.setDuration(END_TIME); topTranslateAnimation.setFillAfter(true); //改变透明度 AlphaAnimation alphaAnimation=new AlphaAnimation(1,0); alphaAnimation.setDuration(END_TIME); //两个动画添加到动画集合中 AnimationSet animationSet=new AnimationSet(true); animationSet.addAnimation(topTranslateAnimation); animationSet.addAnimation(alphaAnimation); startAnimation(animationSet);//开启动画 animationSet.setAnimationListener(new AnimationListener() { @Override public void onAnimationStart(Animation animation) {} @Override public void onAnimationRepeat(Animation animation) {} @Override public void onAnimationEnd(Animation animation){//动画结束隐藏提示的TextView setVisibility(View.GONE); if(animationEnd!=null){ animationEnd.onAnimationEnd(); } } }); } },SHOW_TIME); } /** * 设置标题栏高度 * @param titleHeight */ public void setTitleHeight(int titleHeight) { this.titleHeight = titleHeight; } public void setAnimationEnd(AnimationEndCallback animationEnd) { this.animationEnd = animationEnd; } /** * 动画结束监听函数 * @author apple */ public interface AnimationEndCallback{ public void onAnimationEnd(); }可以借鉴参考下。

版权说明:
本网站凡注明“广州京杭 原创”的皆为本站原创文章,如需转载请注明出处!
本网转载皆注明出处,遵循行业规范,如发现作品内容版权或其它问题的,请与我们联系处理!
欢迎扫描右侧微信二维码与我们联系。
·上一条:技术栈是什么意思_CSS学习 | ·下一条:如何查看手机最近所浏览过哪些网页_CSS学习

Copyright © 广州京杭网络科技有限公司 2005-2025 版权所有    粤ICP备16019765号 

广州京杭网络科技有限公司 版权所有