PopupWindow简单动画弹窗

PopupWindow简单动画弹窗

2023年7月15日发(作者:)

PopupWindow简单动画弹窗写在前⾯主要感觉⾃⼰对于博客这个东西感觉很⼿⽣,现拿⼀些简单的东西来练练⼿,先练练等级,然后再去做⼀些分析类的⽂章,这样可能会好⼀点,感觉abcd的代码居然⽐中⽂的博客还好写,我也是服了我⾃⼰内容先来⼀个简单的PopupWindow弹出效果,主要是showAtLocation()和showAsDropDown()显⽰的动画效果不同,所以就需要进⾏统⼀⼀下。主要思路:因为PopupWindow其实也是⼀个View,所以只要show()的时候对布局显⽰的时候开始动画,dimiss()的时候开始关闭动画就可以代码动效 就是简单的上下偏移的动画 这⾥是可以⾃⼰设置 private Animation createVerticalAnimation(float fromY, float toY) { Animation animation = new TranslateAnimation(VE_TO_SELF, 0f, VE_TO_SELF, 0f, VE_TO_SELF, fromY, VE_TO_SELF, toY); ation(300); erpolator(new DecelerateInterpolator()); return animation; }⾃定义Show⽅法public void showPopupWindow(View v) { //获取控件的位置坐标 ationOnScreen(location); //获取⾃⾝的长宽⾼ e(IFIED, IFIED); //获取屏幕⾼度 int measuredHeight = suredHeight(); int measuredWidth = suredWidth(); int width = suredWidth(); //如果在⼀半的上⽅ 显⽰在下⾯ 在⼀半的下⽅显⽰在上⾯ if (location[1] > eenHeight() / 2) { showAnim = createVerticalAnimation(1, 0); hideAnim = createVerticalAnimation(0, 1); nimation(showAnim); Location(v, _GRAVITY, (location[0] - measuredWidth + width), location[1] - measuredHeight-20); } else { showAnim = createVerticalAnimation(-1, 0); hideAnim = createVerticalAnimation(0, -1); nimation(showAnim); DropDown(v, -measuredWidth + width, 20); } mationListener(new AnimListener() { @Override public void onAnimationEnd(Animation animation) { s(); } }); }完整代码,布局就不贴了/** * title:点击更多弹窗效果 * tip: * * @author zhou * @date 2018-10-29 上午10:15 */public class CirclePopupWindow extends PopupWindow { private List mData; private Context mContext; private View mRootView; private Animation showAnim, hideAnim; public CirclePopupWindow(Context context, List list) { super(context); mContext = context; mData = list; initialize(); } private void initialize() { mRootView = (mContext).inflate(indow, null); RecyclerView mRvList = ewById(_list); outManager(new LinearLayoutManager(mContext)); RecyclerPopupAdapter adapter = new RecyclerPopupAdapter(); Data(mData); pter(adapter); temClickListener(new ClickListener() { @Override public void onItemClick(BaseQuickAdapter adapter, View view, int position) { if (mData != null) { ort((position).getContent()); } } }); tentView(mRootView); tentView(mRootView); kgroundDrawable(new ColorDrawable(or(mContext, arent))); th(_CONTENT); ght(_CONTENT); usable(true); sideTouchable(true); (); } private int[] location = new int[2]; public void showPopupWindow(View v) { //获取控件的位置坐标 ationOnScreen(location); //获取⾃⾝的长宽⾼ e(IFIED, IFIED); //获取屏幕⾼度 int measuredHeight = suredHeight(); int measuredWidth = suredWidth(); int width = suredWidth(); //如果在⼀半的上⽅ 显⽰在下⾯ 在⼀半的下⽅显⽰在 if (location[1] > eenHeight() / 2) { showAnim = createVerticalAnimation(1, 0); hideAnim = createVerticalAnimation(0, 1); nimation(showAnim); Location(v, _GRAVITY, (location[0] - measuredWidth + width), location[1] - measuredHeight-20); } else { showAnim = createVerticalAnimation(-1, 0); hideAnim = createVerticalAnimation(0, -1); nimation(showAnim); DropDown(v, -measuredWidth + width, 20); } mationListener(new AnimListener() { @Override public void onAnimationEnd(Animation animation) { s(); } }); } @Override public void dismiss() { if (hideAnim != null) { nimation(hideAnim); } else { s(); } } private Animation createVerticalAnimation(float fromY, float toY) { Animation animation = new TranslateAnimation(VE_TO_SELF, 0f, VE_TO_SELF, 0f, VE_TO_SELF, fromY, VE_TO_SELF, toY); ation(300); erpolator(new DecelerateInterpolator()); return animation; } public class AnimListener implements ionListener { @Override public void onAnimationStart(Animation animation) {} @Override public void onAnimationEnd(Animation animation) {} @Override public void onAnimationRepeat(Animation animation) {} public void onAnimationRepeat(Animation animation) {} }}

发布者:admin,转转请注明出处:http://www.yc00.com/web/1689430833a247083.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信