• 点击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;
        }
  • 相关阅读:
    Redis的四种模式,单机、主从、哨兵、集群
    .NET 跨域问题
    C# 利用正则表达式获取富文本框中所有图片路劲
    ActiveMQ入门实例(.NET)
    ActiveMQ的使用以及应用场景
    关于消息队列的使用方法(RocketMQ)
    Redis系列 需要注意事项
    .NET:在线悲观锁、在线乐观锁、离线悲观锁、离线乐观锁代码示例
    C# 简单介绍Redis使用
    API Get跟Post 的区别?
  • 原文地址:https://www.cnblogs.com/cbooy/p/4739905.html
Copyright © 2020-2023  润新知