zoukankan      html  css  js  c++  java
  • PopupWindow-----listview item的点击出现PopupWindow

            /**
             * 设置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;
            }
    }
  • 相关阅读:
    城市漫游-牛客
    同步和阻塞理解
    避免用户多次点击,造成重复提交
    页面不可编辑
    正则表达式-简单实例
    从字符串提取一个列表
    JS对象、基本类型和字面量的区别
    本地数据访问时出现跨域问题Cross origin requests are only supported for protocol schemes: ……
    checkbox操作判断 Jquery选择器
    HTML5经典实例——1基础语法和语义
  • 原文地址:https://www.cnblogs.com/java-g/p/4129694.html
Copyright © 2011-2022 走看看