简体   繁体   中英

How can I launch an activity from a location on the screen, like on the home screen or in recent apps?

I want to create a "maximizing" effect from a dialog into my full activity, so I want the opening animation to show the activity expanding from a box to full size.

The stock launcher has done this this since Jelly Bean (pressing an app shortcut will zoom into the application from that icon's location and the Recent Apps menu has done this since ICS.

Figured it out!

Bundle options = ActivityOptionsCompat.makeScaleUpAnimation(
    findViewById(android.R.id.content),
    findViewById(android.R.id.content).getLeft(),
    findViewById(android.R.id.content).getTop(),
    findViewById(android.R.id.content).getWidth(),
    findViewById(android.R.id.content).getHeight()).toBundle();
    startActivity(intent, options);

It only works on API 16 and above, so put a check for it and use the plain old startActivity for older versions.

Maximize from bottom left corner would be something like this.

<?xml version="1.0" encoding="utf-8"?>
<set
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true"
    android:duration="2000">

    <scale
        android:fromXScale="0"
        android:toXScale="1"
        android:fromYScale="0"
        android:toYScale="1"
        android:pivotX="0%"
        android:pivotY="100%"/>

    <translate android:fromYDelta="100%p"
               android:toYDelta="0%p"/>
</set>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM