为 Pre-Lollipop 设备创建循环显示
Posted
技术标签:
【中文标题】为 Pre-Lollipop 设备创建循环显示【英文标题】:Create Circular Reveal for Pre-Lollipop Devices 【发布时间】:2015-09-18 11:59:12 【问题描述】:第一件事,这和Create circular reveal for pre-Lollipop devices (android)不是同一个问题
我正在使用那里提到的库来创建 Circular Reveal,但它似乎对我不起作用。
XML
<io.codetail.widget.RevealFrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_
android:layout_>
<FrameLayout
android:id="@+id/circBack"
android:layout_
android:layout_
android:background="#ff4081"
android:visibility="invisible"
></FrameLayout>
</io.codetail.widget.RevealFrameLayout>
JAVA
View myView = findViewById(R.id.circBack);
// get the center for the clipping circle
int cx = (myView.getLeft() + myView.getRight()) / 2;
int cy = (myView.getTop() + myView.getBottom()) / 2;
// get the final radius for the clipping circle
int finalRadius = Math.max(myView.getWidth(), myView.getHeight());
SupportAnimator animator = ViewAnimationUtils.createCircularReveal(myView, cx, cy, 0, finalRadius);
animator.setInterpolator(new AccelerateDecelerateInterpolator());
animator.setDuration(1000);
myView.setVisibility(View.VISIBLE);
animator.start();
圆形显示不显示。我的意思是当代码执行时什么都没有发生。
Logcat 显示了这个
07-01 19:15:47.498 27556-27556/com.ledo.ledoapp I/art﹕ Rejecting re-init on previously-failed class java.lang.Class<io.codetail.animation.RevealAnimator$RevealRadius>
07-01 19:15:47.498 27556-27556/com.ledo.ledoapp I/art﹕ Rejecting re-init on previously-failed class java.lang.Class<io.codetail.animation.RevealAnimator$RevealRadius>
07-01 19:15:47.498 27556-27556/com.ledo.ledoapp I/art﹕ Rejecting re-init on previously-failed class java.lang.Class<io.codetail.animation.RevealAnimator$RevealRadius>
07-01 19:15:47.501 27556-27556/com.ledo.ledoapp I/art﹕ Rejecting re-init on previously-failed class java.lang.Class<io.codetail.animation.ViewAnimationUtils$SimpleAnimationListener>
07-01 19:15:47.501 27556-27556/com.ledo.ledoapp I/art﹕ Rejecting re-init on previously-failed class java.lang.Class<io.codetail.animation.ViewAnimationUtils$SimpleAnimationListener>
07-01 19:15:47.502 27556-27556/com.ledo.ledoapp I/art﹕ Rejecting re-init on previously-failed class java.lang.Class<io.codetail.animation.RevealAnimator$RevealFinishedGingerbread>
07-01 19:15:47.502 27556-27556/com.ledo.ledoapp I/art﹕ Rejecting re-init on previously-failed class java.lang.Class<io.codetail.animation.RevealAnimator$RevealFinishedGingerbread>
07-01 19:15:47.502 27556-27556/com.ledo.ledoapp I/art﹕ Rejecting re-init on previously-failed class java.lang.Class<io.codetail.animation.RevealAnimator$RevealFinishedIceCreamSandwich>
07-01 19:15:47.503 27556-27556/com.ledo.ledoapp I/art﹕ Rejecting re-init on previously-failed class java.lang.Class<io.codetail.animation.RevealAnimator$RevealFinishedIceCreamSandwich>
07-01 19:15:47.503 27556-27556/com.ledo.ledoapp I/art﹕ Rejecting re-init on previously-failed class java.lang.Class<io.codetail.animation.RevealAnimator$RevealFinishedJellyBeanMr2>
07-01 19:15:47.503 27556-27556/com.ledo.ledoapp I/art﹕ Rejecting re-init on previously-failed class java.lang.Class<io.codetail.animation.RevealAnimator$RevealFinishedJellyBeanMr2>
但是,如果视图设置为在 XML 文件中可见,则循环显示确实有效,但问题是如果我将视图“circBack”设置为在 XML 中可见,它会从应用程序启动的那一刻,这很正常。
这个问题有什么解决办法吗?
【问题讨论】:
【参考方案1】:看起来您正在“Gone”视图上初始化此动画?
尝试获取视图的可见性并确保在内部运行它
if (mView.getVisibility() == View.VISIBLE)
..
..
anim.start();
代码块。
【讨论】:
我将视图设置为“不可见”而不是“消失”。 是的,我说它只是作为参考。当您在不可见或消失的视图上调用动画时会出现这种错误。【参考方案2】:好吧,当我以这种方式添加库时,Gradle 依赖项可能会出现问题,
错误的方式
dependencies
compile ('com.github.ozodrukh:CircularReveal:2.0.1@aar')
transitive = true;
正道
dependencies
compile 'com.github.ozodrukh:CircularReveal:2.0.1'
抱歉,回复晚了。希望对有需要的人有所帮助。
【讨论】:
以上是关于为 Pre-Lollipop 设备创建循环显示的主要内容,如果未能解决你的问题,请参考以下文章
用于 Pre-Lollipop 设备的具有弯曲背景的 Android Ripple 按钮
在Pre-Lollipop设备中使用.xml向量时,应用程序崩溃Xamarin.Android
Media Session Compat 未在 Pre-Lollipop 上显示锁屏控件
如何为 Pre-lollipop 实现 Material-design Elevation