我正在尝试从我的列表到详细信息页面创建一个很好的转换效果,然后从详细信息按回到列表页面。类似的东西:
+----------+ +--------+ A | All from same direction +------+ B | | | A | +--> | | | | | | | | | | +--> | | +------+ | | +--------+ | +----------+ +--------+ +----------+ | B |---+ +----| A | | | A | | B | | | | | | | | | | | | | | | | | | | | | +---> | | | | | | | | <----+ | | | | | | | | |---+ +----| | +--------+ | | +----------+ B moves over A, then after pressing back A moves over B.
第一部分运作良好(列出&gt;细节)但是我在后面的动作上挂钩了相反的效果顺序,它有点起作用,但不是我想要的。错误的页面(第B页)在后退后进行滑动,结束A,然后消失。
我真正想要的是A在背压后滑过B,这更有意义。
列表中的代码:
lstBooks.setOnItemClickListener(new ListView.OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> adapter, View view, int position, long id)
{
Intent intent = new Intent(BooksActivity.this, DetailClass.class);
startActivity(intent);
overridePendingTransition(R.anim.left_to_right_slide, R.anim.right_to_left_slide);
}
});
与详细信息页面相反:
@Override
public void onBackPressed()
{
super.onBackPressed();
overridePendingTransition(R.anim.left_to_right_slide, R.anim.right_to_left_slide);
}
从左到右滑动:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false">
<translate android:fromXDelta="-100%"
android:toXDelta="0%"
android:fromYDelta="0%"
android:toYDelta="0%"
android:duration="350"/>
</set>
从右到左幻灯片:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false">
<translate android:fromXDelta="0%"
android:toXDelta="100%"
android:fromYDelta="0%"
android:toYDelta="0%"
android:duration="350" />
</set>
基本上我希望幻灯片在按下时能够以相反的方向自然地工作。 **
答案 0 :(得分:3)
有4种不同的动画场景:
******************
* *
Left ==*==> Center *
* *
******************
******************
* *
* Center ==*==> Right
* *
******************
******************
* *
Left <==*== Center *
* *
******************
******************
* *
* Center <==*== Right
* *
******************
因此,您需要定义4个动画:
<强> left_to_center_slide 强>
android:fromXDelta="-100%"
android:toXDelta="0%"
<强> center_to_right_slide 强>
android:fromXDelta="0%"
android:toXDelta="100%"
<强> center_to_left_slide 强>
android:fromXDelta="0%"
android:toXDelta="-100%"
<强> right_to_center_slide 强>
android:fromXDelta="100%"
android:toXDelta="0%"
然后:
列表到详细信息:
overridePendingTransition(R.anim.left_to_center_slide,
R.anim.center_to_right_slide);
详情列表:
overridePendingTransition(R.anim.right_to_center_slide,
R.anim.center_to_left_slide);
答案 1 :(得分:0)
试试这个:
@Override
public void onBackPressed()
{
super.onBackPressed();
overridePendingTransition(null, R.anim.right_to_left_slide);
}
从右到左幻灯片:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false">
<translate android:fromXDelta="100%"
android:toXDelta="0%"
android:fromYDelta="0%"
android:toYDelta="0%"
android:duration="350" />
</set>