Activity transition ignoring Toolbar

2019-09-16 10:06发布

问题:

let's see if someone can help me with this.

In my app I have successfully implemented slide transitions between most of my activities. All my activities layouts consist in a regular toolbar and some content below. So what I would like is the animations to ignore the toolbar and only affect the main content.

Ideally, the toolbar would remain in its place and the main content of the layout would be the one sliding.

For completion of the question, here is one of my transition xmls:

<?xml version="1.0" encoding="utf-8"?>

<translate
    android:duration="500"
    android:fromXDelta="100%"
    android:toXDelta="0%" >
</translate>

and this is the way I'm setting transitions:

overridePendingTransition(R.transition.out, R.transition.in);

Thanks

回答1:

Alright, so I found the answer after some hours working on it. I'm having some issues in android 7.1. Other than that, it works in 5.x and 6.x

<?xml version="1.0" encoding="utf-8"?>
<slide
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:slideEdge="right"
    android:duration="500">
    <targets>
        <target android:excludeId="@id/toolbar"/>
        <target android:excludeId="@android:id/statusBarBackground"/>
        <target android:excludeId="@android:id/navigationBarBackground"/>
    </targets>
</slide>

As you can see, you can add views to be ignored by the animation. In my case, the toolbar, status and navigation bar.

Then you can apply the animation the way you prefer, it will affect everything but the elements specified to be ignored.



回答2:

My suggestion is to make a single activity containg toolbar and a container layout, and place fragments inside container and do transition for fragments. It may solve your problem.



回答3:

try adding below code in your style. See if it works

<style name="your_theme_name" parent="your_theme">
<item name="android:windowActionBarOverlay">true</item>
</style>