弹出窗口创建时为弹出项设置动画

时间:2016-11-03 07:59:28

标签: android animation popup

我的布局只有一些呈线性布局的垂直按钮,想要在弹出显示时设置所有按钮的动画,例如所有按钮的动画

    Animation animation = 
    new TranslateAnimation(0, 0, -size, size);
    animation.setDuration(1000);
    animation.setFillAfter(false);
    animation.setInterpolator(new BounceInterpolator());

此代码用于创建弹出窗口

                LayoutInflater inflater = (LayoutInflater) getActivity()
                        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                View layout = inflater.inflate(
                        R.layout.popup_buy,
                        (ViewGroup) getView().findViewById(
                                R.id.popup_element));
                pwindo = new PopupWindow(layout,
                        WindowManager.LayoutParams.FILL_PARENT,
                        WindowManager.LayoutParams.FILL_PARENT, true);
                pwindo.showAtLocation(layout, Gravity.CENTER, 0, 0);

我知道我可以使用此代码访问按钮

                Button btn1 = (Button) layout.findViewById(R.id.btn_opt1);

然而,如何在弹出窗口创建时为所有按钮设置动画?

2 个答案:

答案 0 :(得分:0)

以下代码用于将动画设置为视图

btn1 .startAnimation(animation);

答案 1 :(得分:0)

尝试使用此代码后的任何事情,并用计时器解决了我的问题! :(

            pwindo.setAnimationStyle(R.style.PopUp_Animation);//OPS : 500 ms
            pwindo.showAtLocation(layout, Gravity.CENTER, 0, 0);
            final Button btn1 = (Button) layout.findViewById(R.id.btn);
            final Timer tm = new Timer();
            tm.scheduleAtFixedRate(new TimerTask() {

                @Override
                public void run() {
                    tm.cancel();
                    anim_list_ anim_list = new anim_list_();

                    float loc1 = btn1.getTop();
                    Animation list_v_anim1 = anim_list.list_v(Height,loc2,50);
                    btn1.startAnimation(list_v_anim1);
                }
            }, 1, 550/*550 here !*/);
相关问题