Android Studio XML无法识别objectAnimator

Fut*_*rog 15 xml android android-fragments objectanimator android-studio

我一直试图动画两个片段之间的过渡.我最初在xml中放置了一个属性动画(并没有真正起作用),然后将其更改为objectAnimator.由于某些原因,Android Studio无法识别objectAnimator标记.

这是我的AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.nick.randomapplication" >

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/Theme.Base.AppCompat.Light" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
Run Code Online (Sandbox Code Playgroud)

我的build.Gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 20
    buildToolsVersion "20.0.0"

    defaultConfig {
        applicationId "com.example.nick.randomapplication"
        minSdkVersion 19
        targetSdkVersion 20
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile "com.android.support:appcompat-v7:20.0.+"
}
Run Code Online (Sandbox Code Playgroud)

和xml文件:

<?xml version="1.0" encoding="utf-8"?>

<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android">

</objectAnimator>
Run Code Online (Sandbox Code Playgroud)

感谢您花时间看看这个.我不知道该怎么做了.

小智 43

我认为您已将xml文件放在错误的文件夹中.

valueAnimator objectAnimatoranimatorSet资源应该在文件夹res/animator中,而不是在res/anim中.

请访问android开发者以获取更多信息. http://developer.android.com/guide/topics/resources/animation-resource.html

  • 好吧,我刚刚弄清楚为什么有些人说文件夹应该是"anim"而有些人说"animator".如果您正在为FragmentTransaction和FragmentManager使用v4支持库,则使用名为"anim"的文件夹,对于当前库名称,使用"animator" (2认同)