private class MyAppInfoItemClickListener implements OnItemClickListener{
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position,long id) {
            // 在弹出之前先销毁已经弹出的窗体
            destoryPopupWindow();
            
            //保留当前的Item的位置坐标
            currentIndex = position;
            
            //弹出
            popupWindows(parent,view);
        }
    }

 

    /**
     * 弹出窗体的方法
     * @param parent
     * @param view
     */
    private void popupWindows(AdapterView<?> parent, View view) {
        
        // 展示的View填充
        View contentView = View.inflate(SoftwareManageActivity.this, R.layout.list_item_prop_view, null);
        
        // 获取 展示窗体中的子元素
        getPopupWindowElements(contentView);
        
        // -2 代表wrap_content 
        pwin = new PopupWindow(contentView,-2,-2);
        
        // 弹出窗体在设置动画时要想产生效果必须设置背景
        pwin.setBackgroundDrawable(new ColorDrawable(Color.GRAY));
        
        // Item的位置
        int[] location = new int[2];
        
        view.getLocationInWindow(location);
        
        // Gravity.LEFT | Gravity.TOP   是 与 或的 操作
        pwin.showAtLocation(parent, Gravity.LEFT | Gravity.TOP, DensityUtil.dip2px(this, 60), location[1]);
        
        // 给 展示的 View设置动画
        contentView.setAnimation(animationFactory());
    }

 

    /**
     * 找到弹出窗体里面的子元素并添加监听事件
     * @param contentView
     */
    private void getPopupWindowElements(View contentView) {
        LinearLayout llStart = (LinearLayout) contentView.findViewById(R.id.ll_start_item);
        llStart.setOnClickListener(this);
        
        LinearLayout llShare = (LinearLayout) contentView.findViewById(R.id.ll_share_item);
        llShare.setOnClickListener(this);
        
        LinearLayout llRemove = (LinearLayout) contentView.findViewById(R.id.ll_remove_item);
        llRemove.setOnClickListener(this);
    }

 

    /**
     * 动画工厂
     * @return
     */
    private AnimationSet animationFactory() {
        ScaleAnimation sa = new ScaleAnimation(0.3f, 1.0f, 0.3f, 1.0f, Animation.RELATIVE_TO_SELF, 0,Animation.RELATIVE_TO_SELF, 0.5f);
        
        sa.setDuration(300);
        
        AlphaAnimation aa = new AlphaAnimation(0.5f, 1.0f);
        
        aa.setDuration(300);
        
        AnimationSet animationSet = new AnimationSet(false);
        
        animationSet.addAnimation(sa);
        
        animationSet.addAnimation(aa);
        
        return animationSet;
    }

 

posted on 2015-08-18 16:59  cbooy  阅读(753)  评论(0编辑  收藏  举报