Animate a tint in android via scene transition animation -


so in app, have scene transition on image view transitions 1 activity another:

v.setonclicklistener(new view.onclicklistener() {                     @override                     public void onclick(view v) {                         intent = new intent(v.getcontext(),tracks.class);                         i.putextra("album", al);                         activityoptions transitionactivityoptions = activityoptions.makescenetransitionanimation((item_display) v.getcontext(), cover, "pic");                         v.getcontext().startactivity(i, transitionactivityoptions.tobundle());                     }                 }); 

now, scale , positioning transition works fine. however, on imageview in 2nd activity, have tint attribute in xml make darker (style choice). tint not animate, whole effect more jarring like. there way tint smoothly transition , forth rest of image?

use custom transition. this.

public class tinttransition extends transition {  private static final string propname_tint = "com.example:tinttransition:tint";  public tinttransition(context context, attributeset attrs) {     super(context, attrs); }  private void capturevalues(transitionvalues values) {      if (values.view instanceof appcompatimageview) {         values.values.put(propname_tint, ((appcompatimageview) values.view).getimagetintlist());     }  }  @override public void capturestartvalues(transitionvalues transitionvalues) {     capturevalues(transitionvalues); }  @override public void captureendvalues(transitionvalues transitionvalues) {     capturevalues(transitionvalues); }   @override public animator createanimator(viewgroup sceneroot, final transitionvalues startvalues, final transitionvalues endvalues) {       if (endvalues == null) {         return null;     }      if (!(endvalues.view instanceof appcompatimageview)) {         return null;     }       colorstatelist startcolorstatelist = (colorstatelist) startvalues.values.get(propname_tint);     colorstatelist endcolorstatelist = (colorstatelist) endvalues.values.get(propname_tint);      final int endcolor = endcolorstatelist.getdefaultcolor();     final int startcolor = startcolorstatelist == null             ? color.transparent             : startcolorstatelist.getdefaultcolor();      valueanimator animator = valueanimator.ofobject(new argbevaluator(), startcolor, endcolor);      animator.addupdatelistener(new valueanimator.animatorupdatelistener() {         @override         public void onanimationupdate(valueanimator animation) {             integer color = (integer) animation.getanimatedvalue();             if (color != null) {                 ((appcompatimageview) endvalues.view).setimagetintlist(colorstatelist.valueof(color));              }         }     });       return animator;  } 

}

if need inflate xml, way it:

<?xml version="1.0" encoding="utf-8"?> <transitionset xmlns:android="http://schemas.android.com/apk/res/android">     <transition class="com.example.transitions.tinttransition" android:duration="400" android:interpolator="@android:interpolator/fast_out_slow_in"/> </transitionset> 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -