- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用 AnimationAsState
创建相同的动画, Animatable
, 和 UpdateTransition
并尝试一下。
所有动画都使用向前或向后移动。
tween(
durationMillis = 3000,
easing = LinearOutSlowInEasing
)
我们可以在下面看到
AnimateAsState
似乎是正确的和
Animatable
.然而,令我惊讶的是,
UpdateTransition
似乎没有那样做。我猜它恢复到默认动画持续时间(运行速度非常快)。
UpdateTransition
如果后续动画中途取消,将不会保留正在运行的动画规范? UpdateTransition
错误,需要向 Google 报告吗? import androidx.compose.animation.core.*
import androidx.compose.animation.core.Animatable
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.material.Button
import androidx.compose.material.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
@Composable
fun Combination() {
var enabled by remember { mutableStateOf(false) }
val dbAnimateAsState: Dp by animateDpAsState(
targetValue = switch(enabled),
animationSpec = animationSpec()
)
val dbAnimatable = remember { Animatable(0.dp) }
val transition = updateTransition(enabled, label = "")
val dbTransition by transition.animateDp(
transitionSpec = { animationSpec() }, label = "") {
switch(it)
}
Column(
modifier = Modifier.fillMaxSize(),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Text("AnimateAsState")
animateBoxHorizontal(dbAnimateAsState)
Text("Animatable")
animateBoxHorizontal(dbAnimatable.value)
Text("UpdateTransition")
animateBoxHorizontal(dbTransition)
Button(onClick = { enabled = !enabled }) {
Text("Click Me")
}
}
LaunchedEffect(key1 = enabled) {
dbAnimatable.animateTo(
targetValue = switch(enabled),
animationSpec = animationSpec()
)
}
}
private fun animationSpec(): TweenSpec<Dp> =
tween(
durationMillis = 3000,
easing = LinearOutSlowInEasing
)
private fun switch(enabled: Boolean) = if (enabled) 268.dp else 0.dp
fun Animatable(initialValue: Dp) = Animatable(
initialValue,
DpToVector,
)
private val DpToVector: TwoWayConverter<Dp, AnimationVector1D> =
TwoWayConverter({ AnimationVector1D(it.value) }, { it.value.dp })
@Composable
private fun animateBoxHorizontal(dbAnimateAsState: Dp) {
Box(
modifier = Modifier
.height(32.dp)
.width(300.dp)
.background(Color.Yellow)
) {
Box(
modifier = Modifier
.offset(dbAnimateAsState, 0.dp)
.size(32.dp)
.background(Color.Red)
)
}
Spacer(modifier = Modifier.height(16.dp))
}
注意:更新信息
tweenSpec
更改至
springSpec
IE。
tween(
durationMillis = 3000,
easing = LinearOutSlowInEasing
)
至
spring(stiffness =20f, dampingRatio = 0.25f)
然后
updateTransition
像往常一样工作,当我们用新的动画中断动画时, Spring 速度和动画被保留并连续。
最佳答案
updateTransition
仍然保持速度 - 如果你可以放慢速度可能会更明显。它切换到 spring
被打断时,而 animateAsState
和 Animatable
使用 AnimationSpec
你提供的。那个后备 Spring 可能有点太僵硬了,因此它被认为是一个非常快速的变化。
此设计的目的是允许 Transition
在使用不同类型的 AnimationSpec
时适应中断s。例如,从状态 A 到状态 B,您可能正在使用 keyFrames
,从状态 B 到状态 C 或者可能正在使用 snap()
(因为状态 B 和 C 中的值相同)。因此,当您以 C 作为新目的地从 A -> B 中断动画时,keyframes
和 snap
看起来会很奇怪。这就是我们回退到 spring
的原因。当一个 Transition
被打断。
请注意,如果您已经使用 spring
Transition
中的动画,该 Spring 将用于处理该动画中的中断,因为它与您的动画更相关。这就是为什么当您在上面的代码 fragment 中为过渡提供低刚度 Spring 时,您会看到动画的“路线校正”要慢得多。
我们确实计划支持中断处理的自定义,您可以在其中指定中断时使用的 AnimationSpec。这是计划作为 future 的工作。如果您对如何处理中断有任何具体要求,或者回退 Spring 应该慢一点,请随时提交功能请求。 :)
关于android - 如果更改为新动画,UpdateTransition 动画会保持其运行速度吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71170430/
我在想出一个算法时遇到了麻烦... 我有一系列 GPS 数据,以 1 秒为间隔记录时间、速度、距离。假设距离是米,速度是米/秒。可能有超过 2 小时的数据,或 7200 个点。这里的“时间”字段主要是
使用java排序器,即: Collections.sort(myArrayList, new Comparator() { @Override public int c
有什么区别吗 SELECT * FROM my_table 和 SELECT my_column_id FROM my_table 地点: my_table 有百万行 网站上有大量并发用户进行sql查
有2个样本。 在第一个示例中,使用 orderby 可以更快地获得结果。 (根据 phpmyadmin 速度报告) 在另一个例子中,我没有使用 order by,它给出的结果较慢。 (根据 phpmy
我注意到,如果我将训练数据加载到内存中并将其作为 numpy 数组提供到图中,与使用相同大小的 shuffle 批次相比,速度会有很大差异,我的数据有大约 1000 个实例。 使用内存 1000 次迭
我在 python 中使用破折号。我正在绘制记录到 SQLite 数据库中的实时数据,目前,我正在绘制单个值与时间线图。我计划再添加 20 个图表,但目前,随着时间的增加, plotly 变慢,我认为
我试图调用 hasNext Velocity 模板中的方法,以便根据 foreach 循环中的位置影响行为 - 仅 hasNext没有按照文档工作。 这是 Velocity 用户指南的片段,关于 ha
在我正在制作的游戏中,我有两个点,pt1 和 pt2,我想计算出它们之间的角度。我已经在较早的计算中计算出距离。显而易见的方法是对垂直距离上的水平距离进行反正切 (tan(theta) = opp/a
我经常遇到字符串值不存在和/或为空的情况。这是测试这种情况的最佳方法吗? #if( $incentive.disclaimer && $!incentive.disclaimer != '' )
我想将一个模板nested包含在其他模板cont1,cont2和cont3中。 并且嵌套模板应仅对cont1隐藏一个特定控件。 在包含在cont1中之前,我想为一些标志变量$hideMyControl
是否可以更改从“Windows Azure Media Encoder”输出的音频的播放速度? 我正在使用配置为“WMA High Quality Audio”的“Windows Azure Medi
我使用速度将String(template)与字段合并 hi there I'am ${name}, And I'am ${age} old. velocity将字段${name}和${age}与一种
我使用的是 LockedBitmap 类,它简化了 C# 中位图数据的处理。目前它正在将数据复制到本地 byte[] 数组中,然后通过其类方法访问该数组以获取/设置像素颜色值。 这比直接通过指针访问锁
我尝试在 VM_global_library.vm 文件中添加一堆 #set($x=abc) 语句,但这些变量在我的 VM 模板中不可用。 我想为图像的基本路径等设置一个全局变量。这可能吗? 最佳答案
我的项目结构: -src --main ---java ----makers -----SomeClass ---resources ----htmlPattern.vm 如何告诉 SomeClass
我正在尝试从 Velocity 中的字符串中删除不需要的字符(换行符可以,但不能像 EM 和 CAN ASCII 控制字符那样)。 #set($cleanScreen = $cleanScreen.r
我想在日.月.年之间的点处分割日期。例如:2015 年 1 月 14 日至 {14, 01, 2015}这是我使用的代码:dates3.get(0) 包含我从页面的文本字段获取的字符串“14.01.2
之后,从 1.5 升级到速度引擎 1.7 出现了 1.5 没有的问题。为了解释这个问题,我必须展示一个代码片段: #foreach($someVariable in $someCollection)
我想知道从表中选择所有字段是否更快: SELECT * 或只选择您真正需要的: SELECT field1, field2, field3, field4, field5... 假设表有大约 10 个
我正在尝试模仿照片应用程序的行为,在该应用程序中,用户用手指平移照片并且照片具有一定的速度。由于我不会深入的原因,我不能将 UIScrollView 与它的缩放 UIImageView 一起使用,而是
我是一名优秀的程序员,十分优秀!