开发者

How to keep some of the components fixed when the soft keyboard comes in?

开发者 https://www.devze.com 2023-02-06 08:40 出处:网络
My application is a chat application, and its UI is: Header of the app List View Chat message, input box, and send button

My application is a chat application, and its UI is:

Header of the app

List View

Chat message, input box, and send button

But the problem is when I click the edit text, the soft keyboard comes and pushes everything up, but I need the header to stay on the screen. I've attached the simplified problem images and UI code here. (I can't post multiple links or images in this post because I'm new to Stack Overflow.)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_pare开发者_JAVA百科nt"
    android:orientation="vertical">
    <TextView android:text="Header contents" android:layout_width="fill_parent"
        android:textSize="20sp" android:gravity="center_horizontal"
        android:layout_height="wrap_content" />
    <ListView android:id="@android:id/list" android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:layout_weight="1" />

    <EditText android:text="" android:layout_gravity="bottom"
        android:id="@+id/EditText01" android:layout_width="fill_parent"
        android:layout_height="wrap_content"></EditText>
</LinearLayout>

Android has this requirement in the default messaging app.

Does anyone have any ideas?


The question is quite old, but anyhow - one way to fix this is to put everything that comes below the header within a ScrollView.

Example:

<!-- Both elements below are children of a parent RelativeLayout -->

<RelativeLayout
    android:id="@+id/custom_action_bar"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:isScrollContainer="false" >

    <!-- Header goes here. -->
    <!-- This part remains fixed even with the keypad popping up. -->

</RelativeLayout>

<ScrollView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/custom_action_bar"
    android:isScrollContainer="true" >

    <!-- Rest of the UI -->
    <!-- This part scrolls to accommodate the keyboard -->

 </ScrollView>


The solution described here is the solution. Your fullscreen theme is responsible for Kamil Los not being able to reproduce your issue.

You need to adjust the activity's windowSoftInputMode tag, as described here.

Try adding the tag "android:windowSoftInputMode="adjustResize"" to the offending activity in your application's manifest.


That is quite strange, because I have created a new project, pasted your layout and the header does not disappear in my case (neither in 2.2 emulator nor 1.6).

0

精彩评论

暂无评论...
验证码 换一张
取 消