簡體   English   中英

Android從左到右制作動畫視圖

[英]Android animate view from left to right

我有視圖。 這是用戶可以簽名的地方。 當用戶單擊按鈕時,我想產生某種掃描儀效果-繪圖視圖背景將從左到右變化(掃描的“進度”)。 現在,我創建了一個動畫,但是它一次可以改變整個背景。 我需要使其線性-從左到右。 知道如何實現這種效果嗎? :)

我的觀點 :

 <com.rm.freedrawview.FreeDrawView
        android:id="@+id/draw_layout"
        android:layout_width="400dp"
        android:layout_height="200dp"
        android:background="@drawable/border_background"
        app:paintAlpha="255"
        app:paintColor="@color/black"
        app:paintWidth="2dp"
        app:resizeBehaviour="crop"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="400dp"/>

這是我的動畫:

@OnClick(R.id.next_button)
    public void openActivity(){

        int colorFrom = getResources().getColor(R.color.red);
        int colorTo = getResources().getColor(R.color.black);
        ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
        colorAnimation.setDuration(1000);
        colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

            @Override
            public void onAnimationUpdate(ValueAnimator animator) {
                mDraw.setBackgroundColor((int) animator.getAnimatedValue());

            }

        });
        colorAnimation.start();
    }

您可以檢查此官方鏈接並設置動畫,以查看https://developer.android.com/guide/topics/graphics/prop-animation.html

這是在x軸上移動textview 100點的示例代碼。 您可以像這樣為自己的視圖設置動畫。

 ObjectAnimator animation = ObjectAnimator.ofFloat(textView, "translationX", 100f);
 animation.setDuration(1000);
 animation.start();

或者,您也可以查看此文章 用單個ObjectAnimator更改多個屬性?

這是有關如何執行此操作的完整教程。 http://androideverywhere.in/translate-scale-rotate-alpha-animations/

暫無
暫無

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

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