Android view.animate() 只是跳转到最终位置而不是动画



我有一个基本的测试项目来隔离这个问题。 它只是一个空白的活动,一个中间带有文本视图的框架布局

<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(没有任何变化,它适用于每个组合,缓慢旋转。 下面是我的安卓工作室版本和清单文件。也许您可以尝试使测试项目的缓存失效,并重新启动或清理您的 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-bit Server VM by JetBrains s.r.o Linux 4.15.0-76-generic

我的格拉德尔版本:

格拉德尔-5.4.1-全部.zip

清单.xml

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'
}

原来我在模拟器上禁用了动画。此选项存在的原因是 cuz 动画有时会给 UI 测试带来问题,我们就是这种情况。一年前,我在模拟器上禁用了动画,但完全忘记了它

最新更新