简体   繁体   English

以编程方式更改 AnimatorSet 的 ObjectAnimator 中的值

[英]Change Value in ObjectAnimator of AnimatorSet programmatically

I'd like to change a value of an ObjectAnimator which is part of an AnimatorSet , which is coded in Xml in a designated file in the animator directory.我想更改作为AnimatorSet一部分的ObjectAnimator的值,该值在动画师目录中的指定文件中以 Xml 编码。

I don't want to replace the Xml file with Java code, neither do I want to split it up.我不想用 Java 代码替换 Xml 文件,也不想拆分它。

Is it possible?是否可以?

example code:示例代码:

<set xmlns:android="http://schemas.android.com/apk/res/android">
    <objectAnimator
        android:valueFrom="1.0"
        android:valueTo="0.0"
        android:propertyName="alpha"
        android:duration="0" />

    <objectAnimator
        android:valueFrom="-170"  <!-- I want to change this value on run time -->
        android:valueTo="0"
        android:propertyName="rotationY"
        android:duration="@integer/anim_length" />

    <objectAnimator
        android:valueFrom="0.0"
        android:valueTo="1.0"
        android:propertyName="alpha"
        android:startOffset="@integer/anim_length_half"
        android:duration="0" />

</set>

It's possible.这是可能的。

    AnimatorSet animatorSet = (AnimatorSet) AnimatorInflater.loadAnimator(this, R.animator.anim_yours);

    List<Animator> animators = animatorSet.getChildAnimations();
    for (int i = 0; i < animators.size(); i++) {
        Animator animator = animators.get(i);
        if (animator instanceof ObjectAnimator) {
            ObjectAnimator objectAnimator = (ObjectAnimator) animator;
            if ("rotationY".equals(objectAnimator.getPropertyName())) {
                float fromValue = -100;
                float toValue = 0;
                objectAnimator.setFloatValues(fromValue, toValue);
            }
        }
    }
    // and you use changed AnimoatorSet..

如何以编程方式更改 android 的值: tint 属性<bitmap xml< div><div id="text_translate"><p> 我是新来的,我需要你的帮助。 请告诉我如何从程序级别访问层列表 xml 结构并从程序级别动态更改 bitmap 的“色调”颜色。</p><pre> &lt;layer-list xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;item android:id="@+id/bg_peper" android:right="65dp"&gt; &lt;bitmap android:gravity="top|left" android:tint="@color/red" android:src="@drawable/ic_favorite" /&gt; &lt;/item&gt; &lt;item.... &lt;/layer-list&gt;</pre></div></bitmap> - How to programmatically change the value of the android: tint property in <bitmap xml

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 以编程方式更改xml值 - Change xml value programmatically 如何以编程方式更改 XML 中的值 - How to change a value in XML programmatically 如何以编程方式更改 Slider 的值? (LibGDX) - How to change the value of a Slider programmatically? (LibGDX) 以编程方式更改JavaFX TableView Vertical ScrollBar值 - Change JavaFX TableView Vertical ScrollBar value programmatically 如何以编程方式更改样式属性值? - How to change style attribute value in programmatically? JavaFX:更改以编程方式创建的按钮的值的方法 - JavaFX: Way to change value of programmatically created buttons ObjectAnimator不反转 - ObjectAnimator not reversing 链动画无法与AnimatorSet一起使用 - Chain animations not working with AnimatorSet 如何以编程方式更改 android 的值: tint 属性<bitmap xml< div><div id="text_translate"><p> 我是新来的,我需要你的帮助。 请告诉我如何从程序级别访问层列表 xml 结构并从程序级别动态更改 bitmap 的“色调”颜色。</p><pre> &lt;layer-list xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;item android:id="@+id/bg_peper" android:right="65dp"&gt; &lt;bitmap android:gravity="top|left" android:tint="@color/red" android:src="@drawable/ic_favorite" /&gt; &lt;/item&gt; &lt;item.... &lt;/layer-list&gt;</pre></div></bitmap> - How to programmatically change the value of the android: tint property in <bitmap xml 如何以编程方式将标题栏颜色更改为十六进制值? - How to programmatically change title bar colour to hex value?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM