我试图使用ImageView来淡入一个具有可变持续时间的ViewPropertyAnimator,但是我无法让它正常工作。
这是我用来淡出的代码,它工作得很好:
final ImageView imageView = (ImageView)mView.findViewById(R.id.image_view);
Picasso.with(mView.getContext()).load(mItem.thumbnailURL).into(imageView, new Callback() {
@Override
public void onSuccess() {
imageView.animate().alpha(0).setDuration(duration).start();
}
...
});但是,如果我试图反转方向以使图像消失,图像就永远不会出现:
final ImageView imageView = (ImageView)mView.findViewById(R.id.image_view);
imageView.setAlpha(0);
Picasso.with(mView.getContext()).load(mItem.thumbnailURL).into(imageView, new Callback() {
@Override
public void onSuccess() {
imageView.animate().alpha(1).setDuration(duration).start();
}
...
});为什么alpha值永远不会增加?动画在与setAlpha不同的alpha通道上运行吗?
发布于 2016-09-02 00:50:59
将不推荐的"setAlpha (SetAlpha)“更改为”setAlpha(浮点α)“,它将工作。
imageView.setAlpha(0f);发布于 2018-09-26 07:20:31
使用View.setAlpha(),下面的代码可能会帮助您解决它。
在ViewPropertyAnimator中跟踪源代码
public ViewPropertyAnimator alpha(float value) {
*animateProperty(ALPHA, value);*
...
}然后,
private void animateProperty(int constantName, float toValue) {
float fromValue = *getValue(constantName)*;
...
}就这样,
private float getValue(int propertyConstant) {
final RenderNode node = mView.mRenderNode;
switch (propertyConstant) {
...
case ALPHA:
return *mView.mTransformationInfo.mAlpha;*
}
return 0;
}这和View.setAlpha()有关
public void setAlpha(@FloatRange(float alpha) {
ensureTransformationInfo();
if (mTransformationInfo.mAlpha != alpha) {
*setAlphaInternal(alpha);*
...
}
}与ViewPropertyAnimator.getValue()所指的属性相同:
private void setAlphaInternal(float alpha) {
float oldAlpha = mTransformationInfo.mAlpha;
*mTransformationInfo.mAlpha = alpha;*
...
}https://stackoverflow.com/questions/39282018
复制相似问题