Запустить сцену с помощью TransitionManager в onResume

Можно ли автоматически запускать смену сцены в onResume должным образом? У меня есть макет для деятельности:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="match_parent"
                android:layout_height="match_parent">
    <FrameLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <include layout="@layout/scene0" />
    </FrameLayout>
</RelativeLayout>

И 2 сцены

Сцена 1:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">
    <TextView
        android:id="@+id/test_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Sample text"
        android:textSize="20dp"
        android:layout_centerInParent="true"/>
</RelativeLayout>

сцена 2:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/test_text"
        android:text="Sample text"
        android:textSize="20dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"/>

</RelativeLayout>

Проблема в том, что я не могу вызвать TransitionManager.go(scene2) в onResume(), он просто переходит на вторую сцену без анимации. Но если я опубликую его с обработчиком и сделаю задержку около 100 мс, это сработает.


person MightySeal    schedule 29.07.2015    source источник


Ответы (1)


Для Activity можно использовать метод onWindowFocusChanged. Просто так:

@Override
public void onWindowFocusChanged(final boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);

    if(hasFocus) {
        TransitionManager.go(scene2);
    }
}
person MightySeal    schedule 29.07.2015