Search in sources :

Example 1 with ChangeImageTransform

use of androidx.transition.ChangeImageTransform in project Transitions-Everywhere by andkulikov.

the class ImageTransformSample method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_image_transform, container, false);
    final ViewGroup transitionsContainer = view.findViewById(R.id.transitions_container);
    final ImageView imageView = transitionsContainer.findViewById(R.id.image);
    imageView.setOnClickListener(new View.OnClickListener() {

        boolean mExpanded;

        @Override
        public void onClick(View v) {
            mExpanded = !mExpanded;
            TransitionManager.beginDelayedTransition(transitionsContainer, new TransitionSet().addTransition(new ChangeBounds()).addTransition(new ChangeImageTransform()));
            ViewGroup.LayoutParams params = imageView.getLayoutParams();
            params.height = mExpanded ? ViewGroup.LayoutParams.MATCH_PARENT : ViewGroup.LayoutParams.WRAP_CONTENT;
            imageView.setLayoutParams(params);
            imageView.setScaleType(mExpanded ? ImageView.ScaleType.CENTER_CROP : ImageView.ScaleType.FIT_CENTER);
        }
    });
    return view;
}
Also used : TransitionSet(androidx.transition.TransitionSet) ViewGroup(android.view.ViewGroup) ChangeBounds(androidx.transition.ChangeBounds) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) View(android.view.View) ChangeImageTransform(androidx.transition.ChangeImageTransform) Nullable(androidx.annotation.Nullable)

Aggregations

View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 ImageView (android.widget.ImageView)1 Nullable (androidx.annotation.Nullable)1 ChangeBounds (androidx.transition.ChangeBounds)1 ChangeImageTransform (androidx.transition.ChangeImageTransform)1 TransitionSet (androidx.transition.TransitionSet)1