Android Kotlin“未知的场景名称:transitionManager”第41页308

时间:2018-08-14 18:25:20

标签: android kotlin android-transitions

我正在阅读android studio 3.0开发要点Kotlin版书,并且遇到了问题。

应用程序崩溃,并且在logcat中说“未知场景名称:transitionManager”

由于我是新手,所以我根本不了解这样的简单错误,希望有人可以帮助我解决这个错误。

我正在按照书中的每个步骤进行仔细检查,所以我猜这是书中的错误吗?或书变老了

package com.ebookfrenzy.scenetransitions

import android.os.Build
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.annotation.RequiresApi
import android.transition.Scene
import android.view.View
import android.transition.TransitionManager
import android.transition.TransitionInflater
import android.transition.Transition

import kotlinx.android.synthetic.main.activity_scene_transitions.*

class SceneTransitionsActivity : AppCompatActivity() {

var scene1: Scene? = null
var scene2: Scene? = null
var transitionMgr: Transition? = null

@RequiresApi(Build.VERSION_CODES.KITKAT)
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_scene_transitions)

    transitionMgr = TransitionInflater.from(this)
            .inflateTransition(R.transition.transition)
    scene1 = Scene.getSceneForLayout(rootContainer,
            R.layout.scene1_layout, this)

    scene2 = Scene.getSceneForLayout(rootContainer,
            R.layout.scene2_layout, this)

    scene1?.enter()
}

fun goToScene2(view: View) {
    TransitionManager.go(scene2, transitionMgr)
}

fun goToScene1(view: View) {
    TransitionManager.go(scene1, transitionMgr)
}
}

Logcat

08-14 14:18:25.920 30350-30350/com.ebookfrenzy.scenetransitions E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.ebookfrenzy.scenetransitions, PID: 30350
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ebookfrenzy.scenetransitions/com.ebookfrenzy.scenetransitions.SceneTransitionsActivity}: java.lang.RuntimeException: Unknown scene name: transitionManager
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2957)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3032)
    at android.app.ActivityThread.-wrap11(Unknown Source:0)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696)
    at android.os.Handler.dispatchMessage(Handler.java:105)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6940)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
 Caused by: java.lang.RuntimeException: Unknown scene name: transitionManager
    at android.transition.TransitionInflater.createTransitionFromXml(TransitionInflater.java:181)
    at android.transition.TransitionInflater.inflateTransition(TransitionInflater.java:79)
    at com.ebookfrenzy.scenetransitions.SceneTransitionsActivity.onCreate(SceneTransitionsActivity.kt:27)
    at android.app.Activity.performCreate(Activity.java:7174)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1220)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2910)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3032) 
    at android.app.ActivityThread.-wrap11(Unknown Source:0) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696) 
    at android.os.Handler.dispatchMessage(Handler.java:105) 
    at android.os.Looper.loop(Looper.java:164) 
    at android.app.ActivityThread.main(ActivityThread.java:6940) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374) 
08-14 14:18:25.994 30350-30406/com.ebookfrenzy.scenetransitions I/vndksupport: sphal namespace is not configured for this process. Loading /vendor/lib64/egl/libGLESv2_adreno.so from the current namespace instead.
08-14 14:18:25.999 30350-30406/com.ebookfrenzy.scenetransitions D/libEGL: loaded /vendor/lib64/egl/libGLESv2_adreno.so

项目XML

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/rootContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
       tools:context="com.ebookfrenzy.scenetransitions.SceneTransitionsActivity">

</RelativeLayout>


<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<Button
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="16dp"
    android:layout_marginStart="16dp"
    android:layout_marginTop="16dp"
    android:onClick="goToScene2"
    android:text="@string/one"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<Button
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginEnd="16dp"
    android:layout_marginRight="16dp"
    android:layout_marginTop="16dp"
    android:onClick="goToScene1"
    android:text="@string/two"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<Button
    android:id="@+id/button3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/three"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />
 </android.support.constraint.ConstraintLayout>


 <?xml version="1.0" encoding="utf-8"?>
 <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout_editor_absoluteY="81dp">

<Button
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="19dp"
    android:layout_marginEnd="16dp"
    android:layout_marginRight="16dp"
    android:onClick="goToScene2"
    android:text="@string/one"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent" />

<Button
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="19dp"
    android:layout_marginLeft="16dp"
    android:layout_marginStart="16dp"
    android:onClick="goToScene1"
    android:text="@string/two"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintStart_toStartOf="parent" />

 </android.support.constraint.ConstraintLayout>


<?xml version="1.0" encoding="utf-8"?>
<transitionManager xmlns:android="http://schemas.android.com/apk/res/android">

<changeBounds
    android:duration="2000">
</changeBounds>

 </transitionManager>

1 个答案:

答案 0 :(得分:1)

由于某种原因,我的XML是:

 <?xml version="1.0" encoding="utf-8"?>
 <transitionManager xmlns:android="http://schemas.android.com/apk/res/android">

<changeBounds
android:duration="2000">
</changeBounds>

</transitionManager>

并且应该是

<?xml version="1.0" encoding="utf-8"?>
<transitionSet xmlns:android="http://schemas.android.com/apk/res/android">

    <changeBounds
        android:duration="2000">
    </changeBounds>

</transitionSet>

我不知道为什么创建文件时名称为“ transitionManager”,但是更改为“ transitionSet”可以解决问题。