通告揭示了具有设计库的Android Compat 28 [英] Circular Reveal Android Compat With Design Library 28
问题描述
如何使用设计库版本28在Android中创建圆形显示动画
How To Create A Circular Reveal Animation In Android With Design Library Version 28
我看到了几类他们有这样的话:
I Saw few Classes Which They Are Have Reveal Word Like This Items :
android.support.design.circularreveal.CircularRevealFrameLayout
android.support.design.circularreveal.CircularRevealGridLayout
android.support.design.circularreveal.CircularRevealLinearLayout
android.support.design.circularreveal.CircularRevealRelativeLayout
android.support.design.circularreveal.cardview.CircularRevealCardView
android.support.design.circularreveal.coordinatorlayout.CircularRevealCoordinatorLayout
但是我没有为此找到任何教程
But I Don't Found Any Tutorial For That
请给我一些使用设计库实现这种精美动画的方法
Please Give Me Some Ways To Implement this Beautiful Animation With Design Library
推荐答案
以下是使用支持库的28.0.0版本或新的AndroidX库的方法:
Here's how to do it, with either version 28.0.0 of the Support library, or the new AndroidX library:
private <T extends View & CircularRevealWidget> void circularRevealFromMiddle(@NonNull final T circularRevealWidget) {
circularRevealWidget.post(new Runnable() {
@Override
public void run() {
int viewWidth = circularRevealWidget.getWidth();
int viewHeight = circularRevealWidget.getHeight();
int viewDiagonal = (int) Math.sqrt(viewWidth * viewWidth + viewHeight * viewHeight);
final AnimatorSet animatorSet = new AnimatorSet();
animatorSet.playTogether(
CircularRevealCompat.createCircularReveal(circularRevealWidget, viewWidth / 2, viewHeight / 2, 10, viewDiagonal / 2),
ObjectAnimator.ofArgb(circularRevealWidget, CircularRevealWidget.CircularRevealScrimColorProperty.CIRCULAR_REVEAL_SCRIM_COLOR, Color.RED, Color.TRANSPARENT));
animatorSet.setDuration(5000);
animatorSet.start();
}
});
}
根据您的使用方式,可能不需要发布可运行对象,但这有助于解决两个潜在问题:
Posting the runnable might not be required depending on how you use it, but it helps with 2 potential issues:
- 在调用
CircularRevealCompat.createCircularReveal
时,需要将View附加到窗口
- 我的示例代码计算视图的中间位置,该位置需要视图的宽度和高度,并且帖子始终在视图的
onLayout
之后运行,因此这些内容将始终以这种方式可用.
- The View needs to be attached to the window at the point of calling
CircularRevealCompat.createCircularReveal
- My example code calculates the middle of the View, which requires the View's width and height, and the post always runs after the View's
onLayout
so those will always be available this way.
知道显示是从视图的中间开始的,我们还知道,当显示圆的半径等于视图对角线的一半时,视图将被完全显示.
Knowing that the reveal starts from the middle of the View, we also know that the View will be fully revealed when the radius of the reveal circle equals half of the View's diagonal.
CircularRevealCompat.createCircularReveal
返回一个Animator
,类似于以前的方式(ViewAnimationUtils.createCircularReveal
).
CircularRevealCompat.createCircularReveal
returns an Animator
, similar to the old way of doing it (ViewAnimationUtils.createCircularReveal
).
默认情况下,显示动画上没有稀松布颜色.如果要在显示视图"时设置稀松布的颜色动画,则需要特殊属性CircularRevealWidget.CircularRevealScrimColorProperty.CIRCULAR_REVEAL_SCRIM_COLOR
By default, there is no scrim color on the reveal animation. If you want to animate the scrim color as the View is being revealed, you need an ObjectAnimator
of the special property CircularRevealWidget.CircularRevealScrimColorProperty.CIRCULAR_REVEAL_SCRIM_COLOR
您也可以通过交换startRadius和endRadius(以及稀松布的开始和结束颜色)来轻松创建反向动画.
You can easily create the reverse animation as well by swapping the startRadius and endRadius (and the scrim's start and end colors).
这篇关于通告揭示了具有设计库的Android Compat 28的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!