自定义popWindow布局

一,前述:

进来做项目使用到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);
        }
    });

三:代码实现(未完待续)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值