【发布时间】:2016-07-09 22:11:54
【问题描述】:
我正在尝试在我的视图上运行循环显示动画。我在其他项目中对此有一些经验,但现在我无法启动此代码。
private fun openRevealView() {
val animatedView = activity.findViewById(R.id.a_view);
animatedView.visibility = View.VISIBLE
var cx = (animatedView.getLeft() + animatedView.getRight()) / 2;
var cy = (animatedView.getTop() + animatedView.getBottom()) / 2;
val finalRadius = Math.max(animatedView.height, animatedView.width)
val anim = ViewAnimationUtils
.createCircularReveal(animatedView, cx, cy,
0.toFloat(),
finalRadius.toFloat())
Ln.i("Reveal animation params ["
+ animatedView.height
+ " " + animatedView.width
+ ", 0, " + finalRadius + "]")
anim.start()
}
布局是:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1" />
<android.support.v4.app.FragmentTabHost
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<View
android:id="@+id/a_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/app.red"
android:visibility="invisible" />
</RelativeLayout>
日志是:
显示动画参数 [153 114, 0, 1134]
一切看起来都不错,但没有动画,只有简单的可见/不可见动作。 我也尝试添加监听器,所以效果也很好。 我的另一个项目有这样的代码,它在同一部手机上的工作方式就像 sharm。
我的安卓配置是
compileSdkVersion 23 buildToolsVersion "23.0.1"
感谢您的帮助。
*这是 Kotlin 代码。但这不是问题,我无法从项目的任何地方开始动画。
【问题讨论】: