簡體   English   中英

Android動畫只能播放一次?

[英]Android animation only works once?

所以我想同時做2個動畫,一個移動文本視圖,一個顯示線性布局(也2個動畫來隱藏它們)。 我有另一個動畫正在按計划顯示/隱藏單獨的布局。 當我執行顯示帶有2個動畫的視圖時,它只能工作一次,它可以很好地隱藏,但隨后又無法工作了。 然后,當我顯示另一個視圖時,它將播放所有3個動畫(並非預期)。 我不知道為什么會這樣? 當我嘗試顯示2個動畫時,它什么也不做,但是當我嘗試其他顯示視圖時,就像將其添加到隊列中並顯示所有3個動畫一樣。

我用於啟動兩個動畫的代碼:

        LinearLayout layoutMsgs = (LinearLayout)findViewById(R.id.layoutMsgs);
        Animation anim = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.msgs_show);
        anim.setAnimationListener(new AnimListener(layoutMsgs, View.VISIBLE)); // sets visibility on animation end
        layoutMsgs.startAnimation(anim);

        TextView tvMsgs = (TextView)findViewById(R.id.tvMsgs);
        Animation tvAnim = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.tvmsgs_show);
        tvMsgs.startAnimation(tvAnim);

隱藏兩個動畫的代碼:

    LinearLayout layoutMsgs = (LinearLayout)findViewById(R.id.layoutMsgs);
    Animation animLayout = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.msgs_hide);
    animLayout.setAnimationListener(new AnimListener(layoutMsgs, View.INVISIBLE));
    layoutMsgs.startAnimation(animLayout);

    TextView tvMsgs = (TextView)findViewById(R.id.tvMsgs);
    Animation animMsgs = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.tvmsgs_hide);

    tvMsgs.startAnimation(animMsgs);

然后這是另一個效果很好的動畫,它只是一個動畫,沒有textView,只是一個布局

        LinearLayout pokeLayout = (LinearLayout)findViewById(R.id.layoutPokes);
        Animation anim = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.poke_show);
        anim.setAnimationListener(new AnimListener(pokeLayout, View.VISIBLE));
        pokeLayout.startAnimation(anim);

那么我該如何解決呢? 抱歉,如果我的解釋不好,我很難解釋所有細節,請索取所有丟失的信息。

通過使用本文中的解決方案來解決Android:使用ObjectAnimator轉換具有View維度的分數值的View

並不是很漂亮,因為我必須為需要移動的每個視圖創建單獨的X轉換和Y轉換文件。最終得到了15個動畫文件。 仍然想知道是否有更好的解決方案

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM