5

I'm working in this login screen, and I want all fields, texts and buttons to resize when the IME is shown. I've already used the android:windowSoftInputMode="adjustResize" on androidManifest.xml, but i'm still getting some elements underneath others.

It wouldn't matter if the TextView "Cadastre Agora" (id= cadastrar) remains covered by the virtual keyboard. But, I want at least EditTexts, their TextViews and the button to be visible.

I found this unanswered question that could be an interesting approach: http: //stackoverflow.com/ questions/6484024/soft-keyboard-keep-one-view-stationary-while-moving-other

thanks for helping!

Screen without IME: http://imageshack.us/photo/my-images/138/semttulo2mr.png/

Screen with IME (TextView1 becomes hidden): http://imageshack.us/photo/my-images/404/semttulo3xw.png/

Stackoverflow is complaining about my code formatting, so i uploaded the xml file here: https ://rapidshare.com /files/1767398103/login.xml And i can't post more than 2 links, thats why I put spaces in them.

Abdurakhmon
  • 2,813
  • 5
  • 20
  • 41
Lucas Jota
  • 1,863
  • 4
  • 24
  • 43

1 Answers1

2

In this case I would say your initial layout (without the keyboard showing) is already problematic. Given you are creating what appears to purely be a login screen it would be acceptable to place all your controls in the top half of the screen and have the keyboard display automatically when the user visits the page. This makes the experience faster for the user and saves you having to come up with a flexible layout.

But if you want to try and make the layout work in both views, you will need to change the spacing to be dynamic between the controls.

For example:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width = "fill_parent"
    android:layout_height = "fill_parent"
    android:orientation="vertical"
    >
    <Space 
        android:layout_height="fill_parent"
        android:layout_width="fill_parent"
        android:layout_weight="1">
        <!-- Username Controls here -->
    <Space 
        android:layout_height="fill_parent"
        android:layout_width="fill_parent"
        android:layout_weight="1">
        <!-- Password Controls here -->
    <Space 
        android:layout_height="fill_parent"
        android:layout_width="fill_parent"
        android:layout_weight="1">
        <!-- Login Button here -->
    <Space 
        android:layout_height="fill_parent"
        android:layout_width="fill_parent"
        android:layout_weight="1">
        <!-- TextView here -->
    <Space 
        android:layout_height="fill_parent"
        android:layout_width="fill_parent"
        android:layout_weight="1">
</LinearLayout>

For this to work properly, all of the vertical padding must be removed from your controls, with the exception of padding between the labels for the textboxes.

Scott
  • 2,593
  • 1
  • 22
  • 23
  • using so many `LinearLayout` is **bad** for performance. @Lucas, try checking the [Android IME options](http://developer.android.com/resources/articles/on-screen-inputs.html) – thepoosh May 08 '12 at 06:50
  • That worked to me :D I've pasted my code below. Thanks @Scott. – Lucas Jota May 08 '12 at 11:48
  • @Thepoosh thanks for the hint, I will try to optimize the app on its next updates. – Lucas Jota May 08 '12 at 11:48
  • Feel free to mark my answer as correct ;-) Glad it worked for you. – Scott May 09 '12 at 00:12
  • I've recently discovered the 'Space' View which can be used as a replacement for the LinearLayout as that is their purpose :-) – Scott May 30 '12 at 04:53
  • I haven't had to use it yet so I don't know how well it work, but here is the reference: http://developer.android.com/reference/android/widget/Space.html – Scott May 31 '12 at 00:32