【发布时间】:2015-03-16 06:57:47
【问题描述】:
我想在我的应用中使用 Reveal Effect。我开始了解它是如何实施的。我从Andoid Developer Blog那里得到了信息。
但是当我在我的代码中更新它时,它没有显示任何效果。
我也尝试使用Demo given by Google 来演示显示效果。但它也没有显示效果。如果我需要添加任何权限或我在做什么错?
我的动画师如下:
View button = rootView.findViewById(R.id.button);
final View shape = rootView.findViewById(R.id.circle);
shape.setClipToOutline(false);
shape.setVisibility(View.INVISIBLE);
// Set a listener to reveal the view when clicked.
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(isShowing==false){
// previously invisible view
// get the center for the clipping circle
int cx = (shape.getLeft() + shape.getRight()) / 2;
int cy = (shape.getTop() + shape.getBottom()) / 2;
// get the final radius for the clipping circle
int finalRadius = Math.max(shape.getWidth(), shape.getHeight());
// create the animator for this view (the start radius is zero)
Animator anim =
ViewAnimationUtils.createCircularReveal(shape, cx, cy, 0, finalRadius);
// make the view visible and start the animation
shape.setVisibility(View.VISIBLE);
anim.setDuration(4000);
anim.start();
}else{
// get the center for the clipping circle
int cx = (shape.getLeft() + shape.getRight()) / 2;
int cy = (shape.getTop() + shape.getBottom()) / 2;
// get the initial radius for the clipping circle
int initialRadius = shape.getWidth();
// create the animation (the final radius is zero)
Animator anim =
ViewAnimationUtils.createCircularReveal(shape, cx, cy, initialRadius, 0);
// make the view invisible when the animation is done
anim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
shape.setVisibility(View.INVISIBLE);
}
});
anim.setDuration(4000);
// start the animation
anim.start();
}
isShowing = !isShowing;
}
});
请告诉我如何实现这个效果。
【问题讨论】:
-
你在哪个版本的android上测试它?
-
API 版本号 20。
-
你在 kitkat 上测试它吗?
-
天啊...是的,它的 Kitkat。但不是在低于 Lollipop 的情况下运行这种效果吗?
-
由于 ART,它们中的大多数都没有被反向移植。例如海拔和波纹。可能揭示是其中之一
标签: android android-layout material-design viewanimator circularreveal