How to keep all fields and texts visible while the soft keyboard is shown

一笑奈何 提交于 2019-12-23 12:00:49

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/10493506/how-to-keep-all-fields-and-texts-visible-while-the-soft-keyboard-is-shown

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!