public class LogoutSettingPopup extends PopupWindow implements OnClickListener {
private Context mContext;
protected final int LIST_PADDING = 10;
private Rect mRect = new Rect();
private final int[] mLocation = new int[2];
@SuppressWarnings("unused")
private int mScreenWidth, mScreenHeight;
private boolean mIsDirty;
private int popupGravity = Gravity.CENTER;
private GlobalClickListener globalClickListener;
TextView tv_logout;
TextView tv_cancel;
public LogoutSettingPopup(Context context) {
this(context, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
}
@SuppressWarnings("deprecation")
public LogoutSettingPopup(Context context, int width, int height) {
this.mContext = context;
setFocusable(true);
setTouchable(true);
setOutsideTouchable(true);
setBackgroundDrawable(new BitmapDrawable());
setSoftInputMode(PopupWindow.INPUT_METHOD_NEEDED);
setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
setAnimationStyle(R.style.popupWindowAnimation_right_to_left_in);
mScreenWidth = DisplayUtil.getScreenWidth(mContext);
mScreenHeight = DisplayUtil.getScreenHeight(mContext);
setWidth(width);
setHeight(height);
setBackgroundDrawable(new BitmapDrawable());
setContentView(LayoutInflater.from(mContext).inflate(
R.layout.popup_logout_setting, null));
initUI();
}
private void initUI() {
tv_logout = (TextView) getContentView().findViewById(R.id.tv_logout);
tv_cancel = (TextView) getContentView().findViewById(R.id.tv_cancel);
tv_logout.setOnClickListener(this);
tv_cancel.setOnClickListener(this);
}
public void show(View view) {
view.getLocationOnScreen(mLocation);
mRect.set(mLocation[0], mLocation[1], mLocation[0] + view.getWidth(),
mLocation[1] + view.getHeight());
if (mIsDirty) {
populateActions();
}
showAtLocation(view, popupGravity, 0, 0);
}
private void populateActions() {
mIsDirty = false;
}
public void setGlobalClickListener(
GlobalClickListener globalClickListener) {
this.globalClickListener = globalClickListener;
}
@Override
public void onClick(View view) {
// TODO Auto-generated method stub
switch (view.getId()) {
case R.id.tv_logout:// 注销
this.globalClickListener.globalOnClick("注销", 0);
break;
case R.id.tv_cancel:// 取消
dismiss();
break;
default:
break;
}
}
}
stytle文件(popupWindow进入和离开动画效果)
@anim/right_to_left_in
@anim/left_to_right_out
anim文件
right_to_left_in.xml