本文主要是介绍popWindow,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
private void showPopWindow(View view) {long time = 1000;// 模糊动画 AlphaAnimation alphaAnimation = new AlphaAnimation(0, 1);alphaAnimation.setDuration(time);alphaAnimation.setFillAfter(true);// 缩放动画 ScaleAnimation scaleAnimation = new ScaleAnimation(0, 1, 0, 1, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);scaleAnimation.setDuration(time);scaleAnimation.setFillAfter(true);// 动画集合 AnimationSet animationSet = new AnimationSet(true);animationSet.addAnimation(scaleAnimation);animationSet.addAnimation(alphaAnimation);//下面是popWindow的部分// 找到布局文件View v = View.inflate(getContext(),R.layout.popup_window_app_mannager, null);PopupWindow popupWindow;popupWindow = new PopupWindow(v,LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT, true);popupWindow.setBackgroundDrawable(new ColorDrawable());popupWindow.showAsDropDown(view, 100, -view.getHeight());// 开始动画v.setAnimation(animationSet);}
分开的
private PopupWindow mPopupFirst; private void initPopWindow_First() {// 找到布局文件View v = View.inflate(getContext(),R.layout.view_see_or_change_iv_user, null);mTv_changephoto = v.findViewById(R.id.tv_changephoto);mTv_show_big = v.findViewById(R.id.tv_show_big);mTv_dissmis = v.findViewById(R.id.tv_dissmis);mPopupFirst = new PopupWindow(v,LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT, true);mPopupFirst.getContentView().measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);mPopupFirst.setBackgroundDrawable(new ColorDrawable());mPopupFirst.setAnimationStyle(R.style.Popupwindow_setPhoto);}private void ShowPopupWindow_First(View view) {mPopupFirst.showAsDropDown(view, view.getWidth() / 2 - mPopupFirst.getContentView().getMeasuredWidth() / 2, -view.getHeight() / 2 - 400);// 开始动画backgroundAlpha(0.5f);mPopupFirst.setOnDismissListener(new PopupWindow.OnDismissListener() {@Overridepublic void onDismiss() {backgroundAlpha(1f);}});}public void backgroundAlpha(float bgAlpha) {WindowManager.LayoutParams lp = getActivity().getWindow().getAttributes();lp.alpha = bgAlpha; //0.0-1.0getActivity().getWindow().setAttributes(lp);getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);}
背景
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"><!-- 圆角半径 --><corners android:radius="20dp" /><!-- 背景颜色 --><solid android:color="#eeeeeeee" /></shape>
style
<style name="my_popwindow"><item name="android:windowEnterAnimation">@anim/pop_in</item><item name="android:windowExitAnimation">@anim/pop_out</item></style>
进入动画
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"><translateandroid:duration="500"android:fromYDelta="100%p"android:toYDelta="0" /><alphaandroid:duration="500"android:fromAlpha="0.0"android:toAlpha="1.0" />
</set>
退出动画
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"><translateandroid:duration="500"android:fromYDelta="0"android:toYDelta="100%p" /><alphaandroid:duration="500"android:fromAlpha="1.0"android:toAlpha="0.0" />
</set>
这篇关于popWindow的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!