2

I've done a lot of reading around SO in an attempt to solve this question, but I haven't quite figured out a great solution to this problem, so here goes.

What I am trying to do is this: I am trying to create a vertical LinearLayout with an EditText, a TextView, and a ListView. I would like the layout to be arranged in such a way such that when the EditText is focused on, the TextView is flush with the top of the keyboard and the keyboard hides the ListView on the bottom. Then, when the keyboard is hidden, the ListView is shown again.

What I have so far (which is currently working, but a terrible ugly hack). Is that I implement the method shown here: How to check visibility of software keyboard in Android? to detect when the keyboard is shown and the remaining size of the viewable area. Then, I calculate the size of all of the fixed-sized elements which are above the keyboard (ActionBar, TextView, and a random ImageView). I then subtract that from the total area available to me, and I set my EditText to be the size of what is left over.

This way, since the EditText is laid out directly above the TextView, it will push the TextView to be the exact right height above the keyboard and leave enough room for everything.

Now, this obviously makes me tremendously uncomfortable, because I'm bound to run into a user with a tiny screen that somehow breaks this ugly hack; however, I haven't been up with a better way to solve this problem. Does anyone have any suggestions for how to do so?

The other solution which I tried is setting the Activity to adjustResize when the soft keyboard is shown and then hiding my ListView. However, because of delays in the timing of when the keyboard is shown/not shown this just ends up looking terribly glitchy.

Edit: I've added a pixel-accurate representation of what I'm looking for.Android layout

Community
  • 1
  • 1
Jonathan
  • 2,701
  • 4
  • 20
  • 25
  • There aren't other ways as the softkeyboard doesn't offer events about its state. Small screens shouldn't be a problem as long as you impose some constraints(like a minimum height). – user Jul 06 '13 at 16:33

0 Answers0