gpt4 book ai didi

java - Android动画 View 从左到右

转载 作者:行者123 更新时间:2023-12-02 02:31:55 26 4
gpt4 key购买 nike

我有绘图 View 。这是用户可以签名的地方。当用户单击按钮时,我想制作某种扫描仪效果 - 绘制 View 背景将从左侧更改为右侧(扫描的“进度”)。现在我创建了一个动画,但它一次性改变了整个背景。我需要使其呈线性 - 从左到右。知道如何实现这种效果吗? :)

我的观点:

 <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();
}

最佳答案

您可以查看此官方链接并为您的 View 添加动画效果 https://developer.android.com/guide/topics/graphics/prop-animation.html

以下是在 x 轴上移动 TextView 100 点的示例代码。您可以像这样为自己的 View 设置动画。

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

或者您可以查看此帖子 Change multiple properties with single ObjectAnimator?

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

关于java - Android动画 View 从左到右,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46948059/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com