<pre name="code" class="html">
if (popupwindow != null&&popupwindow.isShowing()) {popupwindow.dismiss();return;} else {initmPopupWindowView();// popupwindow.showAsDropDown(view, 0, 5);popupwindow.showAsDropDown(view, 0, PARAM.Dp2Px(context, 5));}
<span style="font-family: Arial, Helvetica, sans-serif;"> public void initmPopupWindowView() {</span>
// // 获取自定义布局文件pop.xml的视图
View customView = getLayoutInflater().inflate(R.layout.mystock_detail_popup_window_2,null, false);
// 创建PopupWindow实例,200,150分别是宽度和高度
// popupwindow = new PopupWindow(customView, 300, 360);//180,200
popupwindow = new PopupWindow(customView, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
// 设置动画效果 [R.style.AnimationFade 是自己事先定义好的]
popupwindow.setAnimationStyle(R.style.AnimationFade);
// popupwindow.setOutsideTouchable(true);
// 自定义view添加触摸事件
customView.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (popupwindow != null && popupwindow.isShowing()) {
popupwindow.dismiss();
popupwindow = null;
}
return false;
}
});
img_delet = (ImageView) customView.findViewById(R.id.img_delet);
img_share = (ImageView) customView.findViewById(R.id.img_share);
img_delet.setOnClickListener(this);
img_share.setOnClickListener(this);
}
<style name="AnimationFade">
<!-- PopupWindow左右弹出的效果 -->
<item name="android:windowEnterAnimation">@anim/inuptodown</item>
<item name="android:windowExitAnimation">@anim/outdowntoup</item>
</style>
inputodown.xml
<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="500"
android:fromYDelta="-100%"
android:toYDelta="0" />
</set>
outdowntoup.xml
<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="500"
android:fromYDelta="0"
android:toYDelta="-100%" />
</set>