zoukankan      html  css  js  c++  java
  • 点击ListView一个Item弹出窗体,窗体展示时添加动画效果切入

        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;
        }
  • 相关阅读:
    Class.forName()用法详解 【转】
    Java ——代理模式[转发]
    Java堆和栈的区别
    CSS中文字体的英文名称(simsun)宋体,(Microsoft YaHei)微软雅黑
    学了一个封装的jquery插件,感觉还成
    视差滚动(Parallax Scrolling)效果的原理和实现
    解决jQuery中dbclick事件触发两次click事件
    jquery之stop()的用法
    创意 idea
    软件开发方法的综述
  • 原文地址:https://www.cnblogs.com/cbooy/p/4739905.html
Copyright © 2011-2022 走看看