我正在尝试使用ViewPropertyAnimator淡化ImageView
具有可变持续时间的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();
}
...
});
但如果我试图改变淡入的方向,则图像永远不会出现:
setAlpha
为什么alpha值永远不会增加?动画是否在与var ip = '24.210.99.1'; // your IP
var arr = ip.split('.'); // split on DOT
arr[2] = arr[3] = '*'; // set 3rd and 4th element of array to *
var masked = arr.join('.'); // join by DOT again to get masked string
//=> "24.210.*.*"
不同的Alpha通道上运行?
答案 0 :(得分:1)
将已弃用的“setAlpha(int alpha)”更改为“setAlpha(float alpha)”,它将起作用
imageView.setAlpha(0f);
答案 1 :(得分:0)
使用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;*
...
}