活动之间的动画,其中一个是singleTask

时间:2016-07-14 09:23:04

标签: android xml android-activity android-animation android-transitions

我正在开发一个聊天应用程序,并且无法确定如何在两个活动之间进行正确动画制作。我已经用谷歌搜索了一段时间,并且也搜索过它,但如果这个问题已经得到解答,请提前对不起。

我有一个<script type="text/javascript"> function addChoice( last_id ) { var choice = document.createElement( "input" ); choice . setAttribute( "type", "text" ); var p = document.createElement( "p" ); p . innerHTML = last_id + "."; var form = document.getElementById( "new_questions" ); form . appendChild( p ); form . appendChild( choice ); for( var i = 0; i < 1; i ++ ) { var br = document.createElement( "br" ); form . appendChild( br ); } } </script> <?php $subjects = $mysql->query( "SELECT * FROM subjects" ); $questionNr = $_POST["question"]; $question = $mysql->query( "SELECT * FROM questions WHERE question_number='$questionNr';" ); $row = mysqli_fetch_assoc( $question ); $choices = $mysql->query( "SELECT * FROM choices WHERE question_number='$questionNr';" ); ?> <main> <div class="container"> <form id="quizzer_edit" method="post" action="process_edit.php"> <label>Subject</label> <select name="subject"> <?php while( $rowSubject = mysqli_fetch_assoc( $subjects ) ) { ?> <option <?php if( $row["subject"] == $rowSubject["shortcut"] ) echo 'selected="selected"' ?> value=<?php echo $rowSubject["shortcut"] ?>><?php echo $rowSubject["name"] ?></option> <? } ?> </select><br> <p><?php echo $row["text"]; ?></p> <input type="text" name="new_question"/> <?php while( $row = mysqli_fetch_assoc( $choices ) ) { ?> <p><?php echo $row["id"].".".$row["text"]; ?></p> <input type="text" name=<?php echo $row["id"]; $last_id = $row["id"];?>/> <strong>Correct </strong> <input type="checkbox" name="is_correct"/> <?php } ?> <div id="new_questions"></div> <br> <input type="button" value="Add choice" onclick="addChoice(<?php echo ++$last_id; ?>)"/><input type="submit" value="Submit"/> </form> </div> </main> <?php } ?> ,其中包含一个包含聊天列表的片段和一个ChatMainActivity,其中包含一个包含聊天消息的片段。如下所示,我在AndroidManifest.xml中将ChatMainActivity声明为ChatContentFragmentActivity

launchMode="singleTask"

这些是我的动画.xmls:

<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" />

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>

中的聊天记录的Adapter的{​​{1}}中
RecyclerView

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); } 没有做任何事情。

我现在似乎无法找到一个SO问题,这表明,singleTask在这里是一个问题,但我记得解决方案在这个问题中没有帮助我。

有谁知道我如何获得退出并输入我ChatContentFragmentActivity的动画?

编辑:这就是目前的情况:Animation at the moment

1 个答案:

答案 0 :(得分:0)

使用它。

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>

在适配器中使用这个........

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

在ChatContentFragmentActivity类onBackPressed()方法中使用它.......

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

对于键盘,只需在EditText ChatContentFragmentActivity标签中的xml文件中添加这些行....

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

享受编码..........