[英]Android view.animate() just jumps to final position instead of animating
我有一个基本的测试项目来隔离这个问题。 它只是一个空白的 Activity,一个中间有文本视图的 FrameLayout
<FrameLayout
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"
tools:context=".MainActivity">
<TextView
android:background="#88f"
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:layout_gravity="center"
/>
在我的活动中我这样做
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
textView1.setOnClickListener {
it.animate().rotationBy(45f).setDuration(2000).start()
}
}
}
但不是视图缓慢旋转到 45 部分,它只是跳到最终位置而不实际动画。
这曾经在任何地方都像魅力一样工作......但现在突然间它不起作用了。
这是我的 build.gradle 以防它是一个库版本的东西
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.siavashb.testapp"
minSdkVersion 17
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-
rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
我只是按原样测试了您的代码; 在 api21 平板电脑、api24 和 api29 手机上,它就像一个魅力。 还将编译 sdk 更改为 29 并使用/不使用 java 1.8 进行编译,尝试使用 androidX 工件,将 kotlin 插件版本更改为 1.0(当前为 1.3)没有任何变化,它适用于每个组合,缓慢旋转。 下面是我的 Android Studio 版本和清单文件。 也许您可以尝试使您的测试项目的缓存无效并重新启动或清理您的 gradle 目录。 希望能帮助到你。
安卓工作室:
Android Studio 3.5.3 Build #AI-191.8026.42.35.6010548,构建于 2019 年 11 月 15 日 JRE: 1.8.0_202-release-1483-b49-5587405 amd64 JVM: OpenJDK 64-Bitrain Servers4s4ro VM by .Linux -76-通用
我的摇篮版本:
gradle-5.4.1-all.zip
清单文件
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.siavashb.testapp"
minSdkVersion 17
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
// implementation 'androidx.appcompat:appcompat:1.1.0'
// implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
// androidTestImplementation 'androidx.test.ext:junit:1.1.1'
// androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
原来我在模拟器上禁用了动画。 这个选项存在的原因是因为动画有时会导致 UI 测试出现问题,我们就是这种情况。 一年前我在模拟器上禁用了动画,然后完全忘记了
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.