簡體   English   中英

如何在Android中實現從左到右的動畫

[英]How to achieve Left to Right animation in Android

我想在我的應用程序中Left to Right Arrow Animation ,如下圖所示: 在此處輸入圖片說明

我試過下面的代碼:

    ImageView arrowImage = sbView.findViewById(R.id.arrowID);
    ScaleAnimation scale = new ScaleAnimation(0.5f, 0.5f, 1, 1, ScaleAnimation.RELATIVE_TO_SELF, .5f,
            ScaleAnimation.RELATIVE_TO_SELF, .5f);
    scale.setDuration(700);
    scale.setRepeatCount(INFINITE);
    scale.setRepeatMode(REVERSE);
    scale.setFillAfter(true);
    scale.setInterpolator(new OvershootInterpolator());
    arrowImage.startAnimation(scale);

但是我的代碼不符合我的期望。 我嘗試了與Internet不同的解決方案,但未取得結果。

這是翻譯,請嘗試TranslateAnimation

TranslateAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta)

動畫XML文件

<set
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/linear_interpolator"
    android:fillAfter="true">

   <translate
        android:fromXDelta="-10%p"
        android:toXDelta="10%p"
        android:duration="1200" />
</set>

加載此動畫

viewObject.startAnimation(AnimationUtils.loadAnimation(activity, R.anim.filename));

對於手柄移動位置,請使用XML屬性fromXDeltatoXDelta更改值

  • android:fromXDelta

浮動或百分比。 起始X偏移量。 表示為:相對於正常位置的像素(例如“ 5”),相對於元素寬度的百分比(例如“ 5%”)或相對於父寬度的百分比(例如“ 5%p”) )。

  • android:toXDelta

浮動或百分比。 結束X偏移。 表示為:相對於正常位置的像素(例如“ 5”),相對於元素寬度的百分比(例如“ 5%”)或相對於父寬度的百分比(例如“ 5%p”) )。

有關更多有用的信息,請訪問動畫資源

暫無
暫無

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

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