我希望更改ObjectAnimator
的值,AnimatorSet
是<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>
的一部分,在动画目录的指定文件中以Xml编码。
我不想用Java代码替换Xml文件,我也不想将其拆分。
有可能吗?
示例代码:
public static string ToCamelCase(string s)
{
if (string.IsNullOrEmpty(s) || !char.IsUpper(s[0]))
{
return s;
}
char[] chars = s.ToCharArray();
for (int i = 0; i < chars.Length; i++)
{
if (i == 1 && !char.IsUpper(chars[i]))
{
break;
}
bool hasNext = (i + 1 < chars.Length);
if (i > 0 && hasNext && !char.IsUpper(chars[i + 1]))
{
// if the next character is a space, which is not considered uppercase
// (otherwise we wouldn't be here...)
// we want to ensure that the following:
// 'FOO bar' is rewritten as 'foo bar', and not as 'foO bar'
// The code was written in such a way that the first word in uppercase
// ends when if finds an uppercase letter followed by a lowercase letter.
// now a ' ' (space, (char)32) is considered not upper
// but in that case we still want our current character to become lowercase
if (char.IsSeparator(chars[i + 1]))
{
chars[i] = ToLower(chars[i]);
}
break;
}
chars[i] = ToLower(chars[i]);
}
return new string(chars);
}
答案 0 :(得分:0)
这是可能的。
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..