Je vois une chose étrange dans ma transition d'élément partagé sur Lollipop. Les éléments partagés scintillent juste avant de commencer à s'animer (voir la vidéo https://www.youtube.com/watch?v=DCoyyC_S-9A )
Je ne sais pas pourquoi cela se produit. Cependant, lorsque j'ajoute <item name="Android:windowSharedElementsUseOverlay">false</item>
à mon thème, je ne vois pas de scintillement mais la transition ne semble pas bonne (on dirait que seulement la moitié de celle-ci anime la seconde moitié de l'animation "cachée").
Autres paramètres de transition:
<item name="Android:windowActivityTransitions">true</item>
<item name="Android:windowContentTransitions">true</item>
<item name="Android:windowAllowEnterTransitionOverlap">true</item>
<item name="Android:windowAllowReturnTransitionOverlap">true</item>
<item name="Android:windowSharedElementEnterTransition">@Android:transition/move</item>
<item name="Android:windowSharedElementExitTransition">@Android:transition/move</item>
Je commence une activité en utilisant ActivityCompat et ActivityOptionsCompat:
ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(ActivityMain.this,
new Pair<View, String>(playButton, getString(R.string.translation_control_button)),
new Pair<View, String>(findViewById(R.id.playerImage), getString(R.string.translation_artwork)));
ActivityCompat.startActivity(this, pendingIntent, options.toBundle());
1ère activité:
<LinearLayout
Android:layout_width="match_parent"
Android:layout_height="match_parent"
Android:orientation="vertical"
Android:id="@+id/main_container">
<include layout="@layout/toolbar"/>
<FrameLayout
Android:id="@+id/activity_main_fragment_container"
Android:layout_width="match_parent"
Android:layout_height="0dp"
Android:layout_weight="1"></FrameLayout>
<TableLayout
xmlns:Android="http://schemas.Android.com/apk/res/Android"
Android:layout_width="fill_parent"
Android:layout_height="45dp"
Android:padding="7dp"
Android:stretchColumns="*"
Android:id="@+id/player_toolboxTable"
Android:background="?colorPrimary">
<TableRow
Android:layout_width="fill_parent"
Android:layout_height="fill_parent"
Android:id="@+id/player_toolbox">
<ImageView
Android:layout_width="wrap_content"
Android:layout_height="wrap_content"
Android:clickable="true"
Android:id="@+id/player_fav"
Android:src="@drawable/rating_not_important"
Android:onClick="playerFav"
Android:background="@drawable/button_selector_semi_white"
/>
<ImageView
Android:src="@drawable/av_pause_over_video"
Android:layout_width="wrap_content"
Android:layout_height="wrap_content"
Android:clickable="true"
Android:id="@+id/player_play"
Android:onClick="playerPlay"
Android:background="@drawable/button_selector_semi_white"
Android:transitionName="@string/translation_control_button"
/>
<ImageView
Android:src="@drawable/social_share"
Android:layout_width="wrap_content"
Android:clickable="true"
Android:id="@+id/player_share"
Android:background="@drawable/button_selector_semi_white"
Android:layout_height="wrap_content"
Android:onClick="playerShare"
/>
<ImageView
Android:src="@drawable/content_save"
Android:layout_width="wrap_content"
Android:clickable="true"
Android:id="@+id/player_record"
Android:background="@drawable/button_selector_semi_white"
Android:layout_height="wrap_content"
Android:onClick="playerRecord"
/>
</TableRow>
</TableLayout>
</LinearLayout>
</com.heinrichreimersoftware.materialdrawer.DrawerFrameLayout>
Deuxième activité:
<LinearLayout 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"
Android:orientation="vertical"
tools:context=".activities.CommunityActivity">
<include layout="@layout/toolbar"/>
<LinearLayout
Android:layout_width="match_parent"
Android:layout_height="0dp"
Android:layout_weight="1"
Android:paddingLeft="@dimen/activity_horizontal_margin"
Android:paddingRight="@dimen/activity_horizontal_margin"
Android:paddingTop="@dimen/activity_vertical_margin"
Android:paddingBottom="@dimen/activity_vertical_margin"
Android:orientation="vertical">
<Button
Android:id="@+id/community_google_plus_group"
Android:text="@string/community_google_plus"
Android:layout_width="match_parent"
Android:layout_height="wrap_content"
Android:drawableLeft="@drawable/ic_action_gplus"
Android:gravity="left|center_vertical"
style="@style/MaterialButton"
/>
<Button
Android:id="@+id/community_google_fb"
Android:text="@string/community_facebook"
Android:layout_width="match_parent"
Android:layout_height="wrap_content"
Android:drawableLeft="@drawable/ic_action_facebook"
Android:gravity="left|center_vertical"
style="@style/MaterialButton"
/>
<Button
Android:id="@+id/community_mail"
Android:text="@string/community_mail"
Android:layout_width="match_parent"
Android:layout_height="wrap_content"
Android:drawableLeft="@drawable/ic_action_gmail"
Android:gravity="left|center_vertical"
style="@style/MaterialButton"
/>
</LinearLayout>
<include layout="@layout/include_mini_player"/>
</LinearLayout>
include_mini_player.xml
<fragment
xmlns:tools="http://schemas.Android.com/tools"
Android:id="@+id/mini_player_fragment"
xmlns:Android="http://schemas.Android.com/apk/res/Android"
Android:name=".fragments.MiniPlayerFragment"
Android:layout_width="fill_parent"
Android:layout_height="72dp"
tools:layout="@layout/fragment_mini_player"/>
fragment_mini_player:
<LinearLayout
xmlns:Android="http://schemas.Android.com/apk/res/Android"
Android:layout_width="match_parent"
Android:layout_height="match_parent"
Android:orientation="horizontal"
Android:background="?colorPrimary"
>
<ImageView
Android:id="@+id/player_artwork"
Android:layout_width="52dp"
Android:scaleType="centerCrop"
Android:layout_height="52dp"
Android:src="@drawable/music_icon"
Android:layout_margin="5dp"
Android:layout_gravity="center_vertical"
Android:transitionName="@string/translation_artwork"
/>
<LinearLayout
Android:layout_width="0dp"
Android:layout_height="wrap_content"
Android:layout_weight="1"
Android:orientation="vertical"
Android:layout_marginLeft="5dp"
Android:layout_gravity="center_vertical">
<TextView
Android:textColor="@Android:color/white"
Android:text=" "
Android:textSize="8pt"
Android:id="@+id/player_song_title"
Android:layout_width="match_parent"
Android:layout_height="wrap_content"
/>
<TextView
Android:textColor="@Android:color/white"
Android:text=" "
Android:textSize="7pt"
Android:id="@+id/player_song_artist"
Android:layout_width="match_parent"
Android:layout_height="wrap_content"
/>
</LinearLayout>
<ImageView
Android:id="@+id/player_play_button"
Android:layout_gravity="center_vertical"
Android:layout_width="42dp"
Android:layout_height="42dp"
Android:layout_marginRight="5dp"
Android:src="@drawable/av_pause_over_video"
Android:background="@drawable/button_selector_semi_white"
Android:transitionName="@string/translation_control_button"
/>
</LinearLayout>
Avez-vous une idée de pourquoi cela se produit?
Hourra! J'ai réussi à résoudre ce problème.
L'écran clignotant est un problème commun décrit ici: écran clignotant sur la transition d'image entre les activités (thx @AlexLockwood)
L'élément partagé clignotant a été provoqué par DrawerLayout. Je commençais bientôt une nouvelle activité. Lorsque j'ai déplacé ActivityCompat.startActivity
Vers la méthode onDrawerClosed
de DrawerLayout.DrawerListener
, Tout a commencé à fonctionner comme un charme.