欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android PopupWindow實現(xiàn)遮罩層效果

 更新時間:2018年10月29日 09:52:45   作者:carter_yu  
這篇文章主要為大家詳細介紹了Android PopupWindow實現(xiàn)遮罩層效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下

此篇博客實現(xiàn)的功能是:點擊界面中的圖片,跳出一個PopupWindow,PopupWindow中含有相應的文字和圖標,并且在顯示PopupWindow的時候,背景為半透明。

看圖描述:點擊加號,跳出PopupWindow,其中包含三個圖片,點擊叉號PopupWindow消失;當PopupWindow顯示的時候,背景為半透明

顯示PopupWindow的代碼

private void showPopupWindow() {
  View view = (LinearLayout) getLayoutInflater().inflate(R.layout.popup_window_layout, null);
  ImageView ivP = (ImageView) view.findViewById(R.id.ivP);
  ImageView ivX = (ImageView) view.findViewById(R.id.ivX);
  ImageView ivClose = (ImageView) view.findViewById(R.id.ivClose);
  LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
    LayoutParams.WRAP_CONTENT);
  ivP.setLayoutParams(params);
  ivX.setLayoutParams(params);
  ivClose.setLayoutParams(params);
  ivClose.setOnClickListener(this);
  popupWindow = new PopupWindow(WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT);
  popupWindow.setContentView(view);
  popupWindow.setFocusable(true);
  popupWindow.setTouchable(true);
  popupWindow.setOutsideTouchable(false);
  popupWindow.showAsDropDown(ivAdd, 0, 0);
  backgroundAlpha(0.4f);
 }
private void backgroundAlpha(float f) {
  WindowManager.LayoutParams lp =getWindow().getAttributes(); 
  lp.alpha = f; 
  getWindow().setAttributes(lp);
 }

backgroundAlpha()方法用于設置PopupWindow顯示后的背景半透明,參數(shù) f 的范圍是0.0~1.0,數(shù)值越大透明度越高。

源碼下載

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

最新評論