键盘抬起时如何调整列表视图的大小? [英] How to resize a listview when the keyboard goes up?

查看:86
本文介绍了键盘抬起时如何调整列表视图的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是没有键盘的屏幕:

http://i.stack.imgur.com/YOnMf.png

但是,当我单击EditText且键盘向上移动时,标题也被弄乱并消失了,因为它也向上移动了:

But when I click on the EditText and the keyboard goes up, the header messes up and disappears because it goes up too:

http://i.stack.imgur.com/zyJ3j.png

这是代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".SecondActivity"
android:background="@color/white">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="55dp"
    android:id="@+id/abs"
    android:orientation="horizontal"
    android:layout_alignParentTop="true"
    android:gravity="center">

        <ImageView
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:id="@+id/btnVoltar"
            android:src="@drawable/inochat"
            android:layout_marginLeft="3dp"/>

        <ImageView
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:id="@+id/usu"
            android:src="@drawable/usuario"
            android:layout_alignParentRight="true"
            android:background="@drawable/foto"
            android:layout_marginRight="2dp"
            android:layout_marginTop="3dp"/>

        <TextView
            android:layout_width="fill_parent"
            android:layout_toLeftOf="@+id/addfavorito"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="Nome"
            android:id="@+id/nomeoutro"
            android:layout_centerVertical="true"
            android:layout_toRightOf="@+id/btnVoltar"
            android:layout_toEndOf="@+id/btnVoltar"
            android:textColor="#000000"
            android:textSize="15dp"
            android:layout_marginLeft="5dp"/>

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="2dp"
            android:src="@drawable/traco"
            android:layout_alignParentBottom="true"/>

        <ImageButton
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:id="@+id/addfavorito"
            android:layout_centerVertical="true"
            android:layout_toStartOf="@+id/usu"
            android:src="@drawable/fav"/>
</RelativeLayout>

<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/swipe_refresh_layout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_above="@+id/llMsgCompose"
    android:layout_below="@+id/abs">

    <ListView
        android:isScrollContainer="false"
        android:layout_above="@+id/llMsgCompose"
        android:id="@+id/txtMensagens"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@null"
        android:divider="@null"
        android:transcriptMode="alwaysScroll">
    </ListView>

</android.support.v4.widget.SwipeRefreshLayout>

<RelativeLayout
    android:id="@+id/llMsgCompose"
    android:layout_width="match_parent"
    android:layout_height="40dp"
    android:background="@color/white"
    android:layout_alignParentBottom="true"
    android:layout_marginBottom="1dp"
    android:gravity="center">

    <EditText
        android:id="@+id/txtMensagem"
        android:layout_width="50dp"
        android:layout_height="fill_parent"
        android:background="@color/bg_msg_input"
        android:textColor="@color/text_msg_input"
        android:paddingLeft="6dp"
        android:paddingRight="6dp"
        android:inputType="text"

        android:layout_alignParentRight="true"
        android:layout_toRightOf="@+id/icone"/>

    <ImageView
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:id="@+id/icone"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:background="@color/bg_msg_input"
        android:src="@drawable/msg"/>
</RelativeLayout>

</RelativeLayout>

推荐答案

尝试在清单中为此活动添加以下内容:

Try adding the following for this activity in Manifest:

android:windowSoftInputMode ="adjustPan"

android:windowSoftInputMode="adjustPan"

android:windowSoftInputMode ="adjustPan" android:windowSoftInputMode ="adjustResize" 之间的区别:

调整大小"

调整了活动窗口的大小,以便为屏幕上的软键盘腾出空间.

The activity's window is resized to make room for the soft keyboard on screen.

"adjustPan"

活动窗口的内容将自动平移,以使当前焦点不会被键盘挡住.这样用户就可以看到他们正在输入的内容.通常,这不如调整大小那么可取,因为用户可能需要关闭软键盘才能进入并与窗口的模糊部分进行交互.

The contents of the activity's window are automatically panned so that the current focus is never blocked by the keyboard. This is so the user can see what they are typing. This is generally less desirable than resizing, because the user may need to close the soft keyboard to get at and interact with obscured parts of the window.

另外,请参阅此博客

http://android-developers. blogspot.com/2009/04/updating-applications-for-on-screen.html

类似

 <activity
   android:label="@string/app_name"
   android:name=".MainActivity" android:windowSoftInputMode="adjustNothing">
   <intent-filter>
     <action android:name="android.intent.action.MAIN" />
     <category android:name="android.intent.category.LAUNCHER" />
   </intent-filter>
 </activity>

这篇关于键盘抬起时如何调整列表视图的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆