PopupWindow指定位置弹出

private PopupWindow mPopupWindow = null;
public static boolean isPopBackPhone = false;

// private int[] locationPhone = new int[2];

@SuppressWarnings("deprecation")
@SuppressLint("InlinedApi")
private void pop_wallet() {
    final View contentView;
    isPopBackPhone = false;
    if (mPopupWindow == null) {
        contentView = LayoutInflater.from(this).inflate(R.layout.pop_wallet_type,
                null);
        mPopupWindow = new PopupWindow(contentView,
                ViewGroup.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        mPopupWindow.setBackgroundDrawable(new BitmapDrawable());
        mPopupWindow.setTouchable(true);
        mPopupWindow.setOutsideTouchable(true);
        mPopupWindow.setFocusable(true);// 设置外部可点击
        mPopupWindow.update();
        contentView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (mPopupWindow.isShowing()) {
                    img_arrow.setImageDrawable(mActivity.getResources().getDrawable(R.mipmap.flow));
                    mPopupWindow.dismiss();
                }
            }
        });
        final TextView txt_type0 = (TextView) contentView
                .findViewById(R.id.txt_type0);
        final TextView txt_type1 = (TextView) contentView
                .findViewById(R.id.txt_type1);
        final TextView txt_type2 = (TextView) contentView
                .findViewById(R.id.txt_type2);
        final View view_line0 = (View) contentView
                .findViewById(R.id.view_line0);
        final View view_line1 = (View) contentView
                .findViewById(R.id.view_line1);
        final View view_line2 = (View) contentView
                .findViewById(R.id.view_line2);
        txt_type0.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                mPopupWindow.dismiss();
            }
        });
        txt_type1.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
               
                mPopupWindow.dismiss();
            }
        });
        txt_type2.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                bussinessType = "brokerageSettled";
                
                mPopupWindow.dismiss();
            }
        });
    }
    mPopupWindow.setAnimationStyle(R.style.TypeSelAnimationFade);
    // findViewById(R.id.view_line_phone).getLocationInWindow(locationPhone);
    // mPopupWindowPhone.showAtLocation(getWindow().getDecorView(),
    // Gravity.NO_GRAVITY, locationPhone[0], locationPhone[1]);
    mPopupWindow.showAsDropDown(findViewById(R.id.view_line));
    mPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {

        @Override
        public void onDismiss() {
            img_arrow.setImageDrawable(mActivity.getResources().getDrawable(R.mipmap.flow));
            mPopupWindow.dismiss();
        }
    });
}
@Override
public boolean onTouchEvent(MotionEvent event) {
    if (mPopupWindow != null && mPopupWindow.isShowing()) {
        img_arrow.setImageDrawable(mActivity.getResources().getDrawable(R.mipmap.flow));
        mPopupWindow.dismiss();
        mPopupWindow = null;
    }
    return super.onTouchEvent(event);
}

背景灰色透明效果
backgroundAlpha(0.7f);
backgroundAlpha(1f);
/**
 * 设置添加屏幕的背景透明度
 *
 * @param bgAlpha
 */
public void backgroundAlpha(float bgAlpha) {
    WindowManager.LayoutParams lp = mActivity.getWindow().getAttributes();
    mActivity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
    lp.alpha = bgAlpha; //0.0-1.0
    mActivity.getWindow().setAttributes(lp);
}
<style name="TypeSelAnimationFade">
    <item name="android:windowEnterAnimation">@anim/typesel_push_top_in</item>
    <item name="android:windowExitAnimation">@anim/typesel_push_top_out</item>
</style>
typesel_push_top_in---------:
<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/linear_interpolator" >

    <scale
        android:duration="100"
        android:fillAfter="true"
        android:fromXScale="1.0"
        android:fromYScale="0.0"
        android:interpolator="@android:anim/linear_interpolator"
        android:pivotX="0.0%"
        android:pivotY="0.0%"
        android:toXScale="1.0"
        android:toYScale="1.0" />

</set>
typesel_push_top_out---------:
<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/accelerate_interpolator" >

    <alpha
        android:duration="@android:integer/config_shortAnimTime"
        android:fromAlpha="1.0"
        android:toAlpha="0.0" />


    <scale
        android:duration="120"
        android:fillAfter="true"
        android:fromXScale="1.0"
        android:fromYScale="1.0"
        android:interpolator="@android:anim/linear_interpolator"
        android:pivotX="0.0%"
        android:pivotY="0.0%"
        android:toXScale="1.0"
        android:toYScale="0.0" />

</set>


                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值