3

Ich entwickle eine Chat-App und habe Probleme herauszufinden, wie man den Übergang zwischen zwei Aktivitäten richtig animieren kann. Ich habe das schon seit einiger Zeit gegoogelt und habe SO auch danach gesucht, aber tut mir leid im Voraus, wenn diese Frage schon beantwortet wurde.Animation zwischen Aktivitäten, von denen eine singleTask ist

Ich habe eine ChatMainActivity, die ein Fragment enthält eine Liste von Chats und eine ChatContentFragmentActivity enthält, die ein Fragment enthält die Chat-Nachrichten enthält. Wie unten zu sehen, habe ich die ChatMainActivity in meiner AndroidManifest.xml als launchMode="singleTask" deklariert.

<activity 
     android:name=".ui.activities.ChatMainActivity" 
     android:launchMode="singleTask" 
     android:theme="@style/AppTheme" 
     android:windowSoftInputMode="adjustResize" /> 
    <activity 
     android:name=".ui.activities.ChatContentFragmentActivity" 
     android:parentActivityName=".ui.activities.ChatMainActivity" 
     android:theme="@style/AppTheme" 
     android:windowSoftInputMode="adjustResize" /> 

Das sind meine Animation .xmls:

chat_content_activity_enter_animation.xml

<set xmlns:android="http://schemas.android.com/apk/res/android"> 
    <translate 
     android:duration="@integer/activity_animation_duration" 
     android:fromXDelta="100%" 
     android:interpolator="@android:anim/decelerate_interpolator" 
     android:toXDelta="0" /> 
</set> 

chat_content_activity_exit_animation.xml

<set xmlns:android="http://schemas.android.com/apk/res/android"> 
    <translate 
     android:duration="@integer/activity_animation_duration" 
     android:fromXDelta="0" 
     android:interpolator="@android:anim/decelerate_interpolator" 
     android:toXDelta="100%" /> 
</set> 

chat_list_activity_enter_animation.xml

<set xmlns:android="http://schemas.android.com/apk/res/android"> 
    <translate 
     android:duration="@integer/activity_animation_duration" 
     android:fromXDelta="-100%" 
     android:interpolator="@android:anim/decelerate_interpolator" 
     android:toXDelta="0" /> 
</set> 

chat_list_activity_exit_animation.xml

<set xmlns:android="http://schemas.android.com/apk/res/android"> 
    <translate 
     android:duration="@integer/activity_animation_duration" 
     android:fromXDelta="0" 
     android:interpolator="@android:anim/decelerate_interpolator" 
     android:toXDelta="-100%" /> 
</set> 

Und hier ist, wie ich sie verwenden:

Im Adapter der RecyclerView enthält, die Chats in ChatMainActivity

Intent intent = new Intent(context, ChatContentFragmentActivity.class); 
context.startActivity(intent); 
activity.overridePendingTransition(R.anim.chat_content_activity_enter_animation, R.anim.chat_list_activity_exit_animation); 

ChatContentFragmentActivity

@Override 
public void finish() { 
    super.finish(); 
    overridePendingTransition(R.anim.chat_content_activity_exit_animation, R.anim.chat_list_activity_enter_animation); 
} 

Mein Problem ist jetzt, dass die Eingabe- und Exit-Animationen der ChatContentFragmentActivity angezeigt werden, aber die ChatMainActivity tut nichts.

Es gab eine SO-Frage, die ich jetzt anscheinend nicht finden kann, die suggerierte, dass singleTask hier ein Problem war, aber ich erinnere mich, dass die Lösung in dieser Frage mir nicht hilft.

Kann jemand wissen, wie ich den Ausgang erhalten und Animation meiner ChatMainActivity spielen kann?

Edit: Dies ist, wie es im Moment aussieht: Animation at the moment

+0

@sushildlh meine bearbeiten f sehen oder ein .gif zeigt, wie es im Moment funktioniert (falsch) – HePa

+0

benutze diesen Link http://www.christianpeeters.com/android-tutorials/tutorial-activity-slide-animation/#more-483 und verbessere dein Knowleadge auch ... viel Spaß beim Codieren – sushildlh

+0

Ich habe versucht, was sie in diesem Tutorial gemacht haben, aber es hat leider nicht geholfen und hat die gleichen Ergebnisse wie im '.gif' ergeben. – HePa

Antwort

0

Verwendung dieser.

pull_right.xml

<?xml version="1.0" encoding="utf-8"?> 
<translate xmlns:android="http://schemas.android.com/apk/res/android" 
    android:duration="300" 
    android:fromXDelta="100%" 
    android:toXDelta="0%" 
    android:interpolator="@android:anim/decelerate_interpolator" 
    /> 

push_left.xml

<?xml version="1.0" encoding="utf-8"?> 
<translate xmlns:android="http://schemas.android.com/apk/res/android" 
    android:duration="300" 
    android:fromXDelta="0%" 
    android:interpolator="@android:anim/decelerate_interpolator" 
    android:toXDelta="-100%" /> 

fade_out.xml

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android"> 
    <alpha 
     android:duration="300" 
     android:fromAlpha="1.0" 
     android:interpolator="@android:anim/accelerate_interpolator" 
     android:toAlpha="0.0" /> 
</set> 

Verwendung in den Adapter dieses ........

Intent intent = new Intent(context, ChatContentFragmentActivity.class); 
context.startActivity(intent); 
activity.overridePendingTransition(R.anim.pull_right, R.anim.push_left); 

Verwendung dieses in der ChatContentFragmentActivity Klasse onBackPressed() Methode .......

@Override 
    public void onBackPressed() { 
     super.onBackPressed(); 
     overridePendingTransition(R.anim.fade_out,0); 
    } 

und für Tastatur fügen Sie einfach diese Zeile in der XML-Datei in EditText Tag von ChatContentFragmentActivity ....

android:focusable="true" 
android:focusableInTouchMode="true" 

genießen Codierung ..........

+0

Obwohl ich es geschafft habe, es in der Zwischenzeit zu arbeiten, wäre dies auch eine brauchbare Lösung gewesen, also werde ich deine Antwort akzeptieren. – HePa

Verwandte Themen