我想在TitleScreenActivity和MainActivity中離開時在android中播放transitionSet。問題是:它只播放淡入淡出的動畫,但不播放其他兩張幻燈片。Android轉換不起作用
這裏是我的代碼:
transition_menu.xml
<?xml version="1.0" encoding="utf-8"?>
<transitionSet xmlns:android="http://schemas.android.com/apk/res/android"
android:transitionOrdering="together"
android:duration="500"
>
<fade xmlns:android="http://schemas.android.com/apk/res/android">
<targets>
<target android:excludeId="@android:id/statusBarBackground"/>
<target android:excludeId="@android:id/navigationBarBackground"/>
</targets>
</fade>
<slide android:slideEdge="top">
<targets>
<target android:targetId="@id/toolbar"/>
</targets>
</slide>
<slide android:slideEdge="bottom">
<targets>
<target android:targetId="@id/bottomSheet"/>
</targets>
</slide>
</transitionSet>
activity_main.xml中
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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"
android:background="@color/colorPrimary"
tools:context="com.rpfsoftwares.multitap.MainActivity">
<include layout="@layout/custom_toolbar"/>
<android.support.v4.view.ViewPager
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/viewPager"
android:elevation="0dp"
android:layout_marginTop="96dp"
android:layout_marginBottom="148dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/bottomSheet"
android:orientation="vertical"
android:layout_width="match_parent"
android:background="@color/colorWhite"
android:weightSum="1"
android:paddingTop="24dp"
android:paddingBottom="24dp"
android:layout_gravity="bottom|center_horizontal"
android:elevation="4dp"
android:layout_height="148dp">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:layout_width="match_parent"
android:weightSum="0.9"
android:id="@+id/bottomTxt"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:layout_weight="0.5"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_gravity="center_vertical"
android:text="@string/bestScore"
android:textAlignment="center"
android:layout_weight="0.3" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_gravity="center"
android:text="@string/totalTaps"
android:textAlignment="center"
android:layout_weight="0.3" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_gravity="center"
android:text="@string/totalTime"
android:textAlignment="center"
android:layout_weight="0.3" />
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:layout_width="match_parent"
android:weightSum="1.8"
android:id="@+id/bottom"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:layout_weight="0.5"
android:layout_height="match_parent">
<ImageView
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_weight="0.3"
android:src="@drawable/ic_blur_circular_grey_24dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_gravity="center_vertical"
android:text="8031 pts"
android:id="@+id/txtPts"
android:layout_weight="0.3" />
<ImageView
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_weight="0.3"
android:src="@drawable/ic_touch_app_grey_24dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_gravity="center_vertical"
android:text="11 125"
android:id="@+id/txtTotalTaps"
android:layout_weight="0.3" />
<ImageView
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_weight="0.3"
android:src="@drawable/ic_timer_grey_24dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_gravity="center_vertical"
android:text="2h 21min"
android:id="@+id/txtTotalTime"
android:layout_weight="0.3" />
</LinearLayout>
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fabBack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:elevation="0dp"
android:transitionName="shared"
app:layout_anchor="@id/bottomSheet"
app:layout_anchorGravity="top|center_horizontal"
app:backgroundTint="@color/colorCyan"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_play_arrow_grey_24dp"
android:elevation="6dp"
android:transitionName="shared"
app:layout_anchor="@id/bottomSheet"
app:layout_anchorGravity="top|center_horizontal"
app:backgroundTint="@color/colorWhite"/>
</android.support.design.widget.CoordinatorLayout>
custom_toolbar.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:weightSum="1"
android:id="@+id/toolbar"
android:elevation="4dp"
android:background="@color/colorWhite"
android:layout_height="96dp">
<ImageView
android:layout_width="96dp"
android:layout_height="96dp"
android:padding="32dp"
android:layout_weight="0.25"
android:layout_gravity="center_vertical"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:src="@drawable/ic_arrow_back_grey_24dp"
android:id="@+id/btnBack" />
<ImageView
android:layout_width="96dp"
android:layout_height="96dp"
android:padding="32dp"
android:layout_weight="0.25"
android:layout_gravity="center_vertical"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:src="@drawable/ic_info_outline_grey_24dp"
android:id="@+id/btnInfo" />
<ImageView
android:layout_width="96dp"
android:layout_height="96dp"
android:padding="32dp"
android:layout_weight="0.25"
android:layout_gravity="center_vertical"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:src="@drawable/ic_share_grey_24dp"
android:id="@+id/btnShare" />
<ImageView
android:layout_width="96dp"
android:layout_height="96dp"
android:padding="32dp"
android:layout_weight="0.25"
android:layout_gravity="center_vertical"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:src="@drawable/ic_volume_up_grey_24dp"
android:id="@+id/btnSound" />
</LinearLayout>
activity_title_screen.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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"
android:fitsSystemWindows="true"
tools:context="com.rpfsoftwares.multitap.TitleScreenActivity">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:gravity="center"
android:id="@+id/linearLayout"
android:background="@color/colorBackground"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#Welcome"
android:id="@+id/txtAppName"
android:layout_gravity="center_horizontal" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="@dimen/fab_margin"
android:src="@drawable/ic_play_arrow_grey_24dp"
android:elevation="6dp"
android:transitionName="shared"
app:backgroundTint="@color/colorCyan" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="tap to start"
android:id="@+id/txtTitle"
android:layout_gravity="center_horizontal" />
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
styles.xml
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:windowContentTransitions">true</item>
<item name="android:windowEnterTransition">@transition/transition_menu</item>
<item name="android:windowExitTransition">@transition/transition_menu</item>
</style>
TitleScreenActivity.java
Intent i = new Intent(TitleScreenActivity.this, MainActivity.class);
ActivityOptionsCompat activityOptions=
ActivityOptionsCompat.makeSceneTransitionAnimation(TitleScreenActivity.this);
ActivityCompat.startActivity(TitleScreenActivity.this,i,activityOptions.toBundle());
或者,您可以保留背景並指定'android:transitionGroup =「false」'。 – keyboardsurfer