android - TransitionDrawable not working inside custom view's onDraw -
i trying start transitiondrawable starttransition() method inside ontouchevent() of custom view. shows first image in xml file. works on imageview
's setdrawable()
method. combining these 2 possible or there other alternative show similar transition in custom view.
transition.xml:
<?xml version="1.0" encoding="utf-8"?> <transition xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/ic_icon_lock"/> // image shown <item android:drawable="@drawable/ic_icon_unlock"/> </transition>
initializer:
mlocktransitionaldrawable = (transitiondrawable) resourcescompat.getdrawable(mresources, r.drawable.transition, mcontext.gettheme());
ondraw() custom view:
mlocktransitionaldrawable.setbounds(mlockrect); mlocktransitionaldrawable.draw(canvas);
fired when action down happens inside rectangle(mlockrect) containing drawable:
mlocktransitionaldrawable.starttransition(1000); // not change drawable layer invalidate() requestlayout() not working either
i looking simple solution because of time constraints.
thanks pskink's comment got working. heres relevant code.
create drawable.callback
object or implement it:
mlocktransitioncallback = new drawable.callback() { @override public void invalidatedrawable(drawable who) { log.e("invalidate called", "yes"); invalidate(mlockrect);// don't call invalidate() invalidate whole canvas invalidating region want redraw } @override public void scheduledrawable(drawable who, runnable what, long when) { new handler().postattime(what, who, when);// start animation } @override public void unscheduledrawable(drawable who, runnable what) { log.e("unschedule called","yes"); } };
set callback:
mlocktransitionaldrawable.setcallback(mlocktransitioncallback);
Comments
Post a Comment