android PopupWindow 阴影背景 、动画 、点击显示、隐藏

阴影背景 bg_shadow_white.xml



    
    
        
            
            
                
                
                
                
            
        
    
    
        
            
            
                
                
                
                
            
        
    
    
        
            
            
            
        
    
    
        
            
            
            
        
    
    
        
            
            
            
        
    
    
    
        
            
            
        
    

 入动画 pop_enter_anim.xml 



    
    

出动画 pop_exit_anim.xml



    
    

动画 样式 

    

点击显示、隐藏

final PopupWindow popupWindow=new PopupWindow(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT);

                popupWindow.setOutsideTouchable(true);
                popupWindow.setFocusable(true);
                popupWindow.setTouchable(true);
                popupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));//部分系统如果不设置透明背景时无法点击外部隐藏
                popupWindow.setAnimationStyle(R.style.popwin_anim_style);
                View view =LayoutInflater.from(context).inflate(R.layout.pop_menu_item,null,false);
                
                popupWindow.setContentView(view);

                int[] location=new int[2];
                iv.getLocationInWindow(location);//iv 为所在屏幕位置
                int x=location[0]-(MainActivity.metrics.widthPixels/2)+dp2px(context,22f);//x 偏移量根据自己需求调节
                int y= location[1]+dp2px(context,25f);//y 偏移量根据自己需求调节
                popupWindow.showAtLocation(iv, Gravity.NO_GRAVITY, x, y);

 

你可能感兴趣的:(android,popupwindow)