Skip to content

Most visited

Recently visited

navigation
XYZTouristAttractions / Application / src / com.example.android.xyztouristattractions / ui /

ScaleTransition.java

1
package com.example.android.xyztouristattractions.ui;
2
 
3
import android.animation.Animator;
4
import android.animation.ObjectAnimator;
5
import android.animation.PropertyValuesHolder;
6
import android.annotation.TargetApi;
7
import android.content.Context;
8
import android.os.Build;
9
import android.transition.TransitionValues;
10
import android.transition.Visibility;
11
import android.util.AttributeSet;
12
import android.view.View;
13
import android.view.ViewGroup;
14
 
15
/**
16
 * A simple scale transition class to allow an element to scale in or out.
17
 * This is used by the floating action button on the attraction detail screen
18
 * when it appears and disappears during the Activity transitions.
19
 */
20
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
21
public class ScaleTransition extends Visibility {
22
 
23
    public ScaleTransition(Context context, AttributeSet attrs) {
24
        super(context, attrs);
25
    }
26
 
27
    public Animator createAnimation(View view, float startScale, float endScale) {
28
        view.setScaleX(startScale);
29
        view.setScaleY(startScale);
30
        PropertyValuesHolder holderX = PropertyValuesHolder.ofFloat("scaleX", startScale, endScale);
31
        PropertyValuesHolder holderY = PropertyValuesHolder.ofFloat("scaleY", startScale, endScale);
32
        return ObjectAnimator.ofPropertyValuesHolder(view, holderX, holderY);
33
    }
34
 
35
    @Override
36
    public Animator onAppear(ViewGroup sceneRoot, View view, TransitionValues startValues,
37
                             TransitionValues endValues) {
38
        return createAnimation(view, 0, 1);
39
    }
40
 
41
    @Override
42
    public Animator onDisappear(ViewGroup sceneRoot, View view, TransitionValues startValues,
43
                                TransitionValues endValues) {
44
        return createAnimation(view, 1, 0);
45
    }
46
}
This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Follow Google Developers on WeChat

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience. (Dec 2017 Android Platform & Tools Survey)