码迷,mamicode.com
首页 > Windows程序 > 详细

PopupWindow-----listview item的点击出现PopupWindow

时间:2014-11-29 01:28:22      阅读:269      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   ar   color   os   sp   on   div   

        /**
         * 设置listview  item的点击事件
         */
    lv_app_manager.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
                if (position == 0) {
                    return;
                } else if (position == (userAppInfos.size() + 1)) { //超过不弹出
                    return;
                } else if (position <= userAppInfos.size()) {// 用户程序
                    int newposition = position - 1;
                    appInfo = userAppInfos.get(newposition);  //appInfo单个对象 
                } else {// 系统程序
                    int newposition = position - 1 - userAppInfos.size() - 1;
                    appInfo = systemAppInfos.get(newposition);    // 点击
                }
                // System.out.println(appInfo.getPackname());
                dismissPopupWindow();
                View contentView = View.inflate(getApplicationContext(),
                        R.layout.popup_app_item, null);
                ll_start = (LinearLayout) contentView
                        .findViewById(R.id.ll_start);
                ll_share = (LinearLayout) contentView
                        .findViewById(R.id.ll_share);
                ll_uninstall = (LinearLayout) contentView
                        .findViewById(R.id.ll_uninstall);  //卸载

                ll_start.setOnClickListener(AppManagerActivity.this);
                ll_share.setOnClickListener(AppManagerActivity.this);
                ll_uninstall.setOnClickListener(AppManagerActivity.this);
                //   得到 PopupWindow 的对象
                popupWindow = new PopupWindow(contentView, -2, -2);   // 上面的contentView 
                // 动画效果的播放必须要求窗体有背景颜色。
                // 透明颜色也是颜色
                popupWindow.setBackgroundDrawable(new ColorDrawable(
                        Color.TRANSPARENT));
                int[] location = new int[2];
                view.getLocationInWindow(location);
                // 在代码里面设置的宽高值 都是像素。---》dip
                int dip = 60;
                int px = DensityUtil.dip2px(getApplicationContext(), dip);
                System.out.println("px=" + px);  //  得到 px 
                popupWindow.showAtLocation(parent, Gravity.LEFT | Gravity.TOP,
                        px, location[1]);
                // 最后加上动画
                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 set = new AnimationSet(false);
                set.addAnimation(aa);
                set.addAnimation(sa);
                contentView.startAnimation(set);
            }
    });


 1.关闭的方法

 private  void   dismissPopupWindow() {
        // 把旧的弹出窗体关闭掉。
        if (popupWindow != null && popupWindow.isShowing()) {
            popupWindow.dismiss();
            popupWindow = null;
        }
}

 

PopupWindow-----listview item的点击出现PopupWindow

标签:style   blog   io   ar   color   os   sp   on   div   

原文地址:http://www.cnblogs.com/java-g/p/4129694.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!