Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Animating layout resize when keyboard open

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

like image 770
Gyome Avatar asked Jun 07 '15 02:06

Gyome


People also ask

How do I know if my Android keyboard is open soft?

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.


1 Answers

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:

  • You add animateLayoutChanges in the parent layout of the editText
  • You add the following code in your activity/view/fragment:


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);
  }

like image 68
Peddro Avatar answered Oct 13 '22 14:10

Peddro