一,前述:
进来做项目使用到popWindow,主要实现两个功能:
其一:布局中添加listView,ListView的adater布局中有EditText
其二:实现动画效果
二,popWindow原理方法简介
1,popWindow的构造方法
//方法一:
public PopupWindow (Context context)
//方法二:
public PopupWindow(View contentView)
//方法三:
public PopupWindow(View contentView, int width, int height)
//方法四:
public PopupWindow(View contentView, int width, int height,boolean focusable)
注意:popwidow没有默认的布局,必须我们手动设置一个contentView。
2,popWindow的显示(3种显示方法)
方法一:showAsDropDown(View anchor):-相对于某个控件下方,无偏移
方法二:showAsDropDown(View anchor, int xoff, int yoff):-相对于某个控件下方,可以设置偏移
方法三:showAtLocation(View parent, int gravity, int x, int y):-相对于父控件下方,可以设置偏移
3,主要方法
public void dismiss()
public void setFocusable(boolean focusable)
public void setTouchable(boolean touchable)
public void setOutsideTouchable(boolean touchable)
public void setBackgroundDrawable(Drawable background)
4,动画的实现
public void setAnimationStyle(int animationStyle)
5,使背景变暗
// 设置背景颜色变暗
final WindowManager.LayoutParams lp = this.getWindow().getAttributes();
lp.alpha = 0.7f;
this.getWindow().setAttributes(lp);
popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
@Override
public void onDismiss() {
lp.alpha = 1f;
MainActivity.this.getWindow().setAttributes(lp);
}
});
三:代码实现(未完待续)