popwindow在view左侧弹出,附加弹出动画

直接代码

 /**
     * 显示popwindow
     *
     * @param pop_option  需要显示的pop样式view
     */
    private void showPopupWindow(View pop_option) {
        mPopupmenuView = new PopupWindow(pop_option, ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
        //设置可点击
        mPopupmenuView.setFocusable(true);
        //设置点击外面会消失
        mPopupmenuView.setOutsideTouchable(true);
        mPopupmenuView.setBackgroundDrawable(new BitmapDrawable());
        //在view左侧出现
        mMoreView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
        int  mShowMorePopupWindowWidth = -mMoreView.getMeasuredWidth();
        int  mShowMorePopupWindowHeight = -mMoreView.getMeasuredHeight();
//mMore 为需要在某个view的左侧出现
        mPopupmenuView.showAsDropDown(mMore,mShowMorePopupWindowWidth-25,mShowMorePopupWindowHeight);
        mPopupmenuView.setAnimationStyle(R.style.Animleft);
        mPopupmenuView.update();
        //设置窗口消失事件
        mPopupmenuView.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {

            }
        });
    }

在styles文件里

<style name="Animleft" parent="@android:style/Animation">
        <item name="android:windowEnterAnimation">@anim/push_left_in</item>
        <item name="android:windowExitAnimation">@anim/push_left_out</item>
    </style>

在res下新建anim文件夹,在这个文件夹下新建push_left_in.xml

<?xml version="1.0" encoding="utf-8"?>
<scale   xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/accelerate_decelerate_interpolator"
    android:fromXScale="0.001"
    android:toXScale="1.0"
    android:fromYScale="1.0"
    android:toYScale="1.0"
    android:pivotX="100%"
    android:pivotY="100%"
    android:duration="300" />

新建push_left_out.xml

<?xml version="1.0" encoding="utf-8"?>
<scale   xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/accelerate_decelerate_interpolator"
    android:fromXScale="1.0"
    android:toXScale="0.001"
    android:fromYScale="1.0"
    android:toYScale="1.0"
    android:pivotX="100%"
    android:pivotY="100%"
    android:duration="300" />

搞定!!

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值