本篇主要富含了对PopupWindow的封装,实现动画弹窗的例子。可用于相册选择、点赞等等。同时封装使用了建造者模式,对于补间动画的运用同样有较高的学习价值。
使用方式:
示例一:用于从底部弹出,仿IOS的弹窗效果。常用语选择相机相册、分类查看等等。
public void showAll(View view) {
if (popupWindow != null && popupWindow.isShowing()) return;
View upView = LayoutInflater.from(this).inflate(R.layout.popup_up, null);
popupWindow = new CommonPopupWindow.Builder(this)
.setView(R.layout.popup_up)
.setWidthAndHeight(ViewGroup.LayoutParams.MATCH_PARENT, upView.getMeasuredHeight())
.setBackGroundLevel(0.5f)//取值范围0.0f-1.0f 值越小越暗
.setAnimationStyle(R.style.AnimUp)
.setViewOnclickListener(this)
.create();
popupWindow.showAtLocation(findViewById(android.R.id.content), Gravity.BOTTOM, 0, 0);
}
示例一
示例二:从控件的上下左右弹出,常用于点赞、撤销等等。
public void showLeftPop(View view) {
if (popupWindow != null && popupWindow.isShowing()) return;
popupWindow = new CommonPopupWindow.Builder(this)
.setView(R.layout.popup_left_or_right)
.setWidthAndHeight(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
.setAnimationStyle(R.style.AnimRight)
.setViewOnclickListener(this)
.create();
popupWindow.showAsDropDown(view, -popupWindow.getWidth(), -view.getHeight()+5);
}
附件:
PopWindowUtil-Demo下载
若附件无法下载,请复制链接地址,在浏览器重新执行即可!!
网友评论