I wonder if there is a way to animate the content of my layout when the keyboard is shown.
At the moment, when I launch my activity, it opens the keyboard, which is animated with a translation, but the rest of my view is just resized with a clunky and awful effect. I thought asking for android:animateLayoutChanges="true"
on my main layout would do the trick, but no. I guess because it only handles the layout changes inside of itself.
So is their any way to make my views translate/resize smoothly when the keyboard is shown/hidden?
PS: I don't want adjustPan, adjustResize is really what I need, I just want it to look better. Thx
Android provides no direct way to determine if the keyboard is open, so we have to get a little creative. The View class has a handy method called getWindowVisibleDisplayFrame from which we can retrieve a rectangle which contains the portion of the view visible to the user.
I realise you asked this question 9 months ago and no one answer it. I've only seen it for the first time now, probably you won't need it but I believe this might be a common issue.
What you need to do is to add, like you said, android:animateLayoutChanges="true"
. The trick here is the following:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
ViewGroup rootView = (ViewGroup) findViewById(R.id.your_root_layout_id);
LayoutTransition layoutTransition = rootView.getLayoutTransition();
layoutTransition.enableTransitionType(LayoutTransition.CHANGING);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With