Reputation: 856
I used Motion Layout for Collapse Layout. Motion layout working perfect as I need but I want to set motion layout animation based on data fit too the screen.
Like if data fit in screen then no need to animation. If data out of the screen then show animation.
Upvotes: 1
Views: 343
Reputation: 1255
For Java version:
public static void enableDisableTransition(MotionLayout motionLayout, RecyclerView recyclerView){
motionLayout.enableTransition(R.id.transition, false);
recyclerView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
if (recyclerView.canScrollVertically(1) || recyclerView.canScrollVertically(-1 )
) {
motionLayout.enableTransition(R.id.transition, true);
}
recyclerView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
});
}
Upvotes: 0
Reputation: 856
Finally I got solution:
motionLogin?.enableTransition(R.id.transitionLogin, false)
constraintLayout.viewTreeObserver.addOnGlobalLayoutListener(object :
ViewTreeObserver.OnGlobalLayoutListener {
override fun onGlobalLayout() {
// If the scrollView can scroll, disable the accept menu item button
if (constraintLayout.canScrollVertically(1) || constraintLayout.canScrollVertically(
-1
)
) {
motionLogin?.enableTransition(R.id.transitionLogin, true)
}
// Remove itself after onGlobalLayout is first called or else it would be called about a million times per second
constraintLayout.viewTreeObserver.removeOnGlobalLayoutListener(this)
}
})
Upvotes: 1