您的位置:首页 > 运维架构

PopupWindow指定位置弹出

2016-04-18 16:39 351 查看
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>



                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: