Android 在动态视图中只获得一次动画效果

发布于 2025-01-05 06:23:00 字数 1389 浏览 4 评论 0原文

我正在膨胀一个视图并将该视图放在另一个视图下方,一切都很好,但动画只是以所需的方式出现一次......当我再次按下按钮放置视图时,它不会像第一次出现的那样出现。

这里是视频

    final Animation a3 = new AlphaAnimation(0.00f, 1.00f);
    a3.setDuration(350);

    LayoutInflater vi = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final View cv = vi.inflate(R.layout.popupview, null);

    final RelativeLayout rl = (RelativeLayout)findViewById(R.id.mainlayout);
    final Button b1 = (Button)findViewById(R.id.button1);
    b1.setOnClickListener(new OnClickListener() {
        public void onClick(View arg0) {


            if(cv!=null){
                rl.removeView(cv);
            }

            RelativeLayout.LayoutParams innerLP = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
            cv.setLayoutParams(innerLP);

            RelativeLayout.LayoutParams params1 = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
            params1.addRule(RelativeLayout.BELOW, b1.getId());
            cv.setLayoutParams(params1);

            cv.startAnimation(a3);
            rl.addView(cv);
            rl.invalidate();            

        }
    });

I am inflating a view and putting the view below another, everything is fine but the animation is just coming once in desired fashion...and when i again press the button to put the view its not coming the way it had appeared first time.

HERE IS THE VIDEO

    final Animation a3 = new AlphaAnimation(0.00f, 1.00f);
    a3.setDuration(350);

    LayoutInflater vi = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final View cv = vi.inflate(R.layout.popupview, null);

    final RelativeLayout rl = (RelativeLayout)findViewById(R.id.mainlayout);
    final Button b1 = (Button)findViewById(R.id.button1);
    b1.setOnClickListener(new OnClickListener() {
        public void onClick(View arg0) {


            if(cv!=null){
                rl.removeView(cv);
            }

            RelativeLayout.LayoutParams innerLP = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
            cv.setLayoutParams(innerLP);

            RelativeLayout.LayoutParams params1 = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
            params1.addRule(RelativeLayout.BELOW, b1.getId());
            cv.setLayoutParams(params1);

            cv.startAnimation(a3);
            rl.addView(cv);
            rl.invalidate();            

        }
    });

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

她如夕阳 2025-01-12 06:23:00

我之前也遇到过同样的问题...... 你可以检查我的帖子

当按下一次时它将开始动画..但是如果你想再次开始动画那么你应该让它停止。

I had gone through same problem before.... You can check my post

It will start animation when it pressed once..but if u want to start again the animation then you should make it stop.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文