【问题标题】:After softkeyboard opens, the screen can't adjust itsef correctly软键盘打开后屏幕无法正确调整
【发布时间】:2013-01-02 20:32:44
【问题描述】:

我阅读了很多与此项目相关的主题,但没有一个能解决我的问题。这是我的聊天屏幕的布局:

<?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/chatPage"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/speech_bg" >

<include
    android:id="@+id/chatHeader"
    layout="@layout/header_chat" />

<RelativeLayout
    android:id="@+id/chatView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/chatHeader" >

    <RelativeLayout
        android:id="@+id/chatBottomView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="@drawable/speech_text_bg"
        android:padding="5dp" >

        <RelativeLayout
            android:id="@+id/chatSendButton"
            android:layout_width="@dimen/chatSendButtonWidth"
            android:layout_height="@dimen/chatSendButtonHeight"
            android:layout_alignBottom="@+id/chatEditText"
            android:layout_alignParentRight="true"
            android:layout_marginLeft="5dp"
            android:background="@drawable/chat_send_btn_selector"
            android:onClick="ChatSendButtonClick" >

            <com.xxx.Utils.MyTextView
                xmlns:customtext="http://schemas.custom.com/android/customtext"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:text="@string/chatSendText"
                android:textColor="#ffffff"
                android:textSize="@dimen/chatSendTextSize" />
        </RelativeLayout>

        <EditText
            android:id="@+id/chatEditText"
            android:layout_width="match_parent"
            android:layout_height="@dimen/editTextHeight"
            android:layout_toLeftOf="@+id/chatSendButton"
            android:background="@drawable/edit_text"
            android:inputType="textMultiLine"
            android:maxLines="5" />
    </RelativeLayout>

    <com.handmark.pulltorefresh.library.PullToRefreshListView
        xmlns:pulltorefresh="http://schemas.custom.com/android/pulltorefresh"
        android:id="@+id/chatList"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/chatBottomView"
        android:cacheColorHint="#00000000"
        android:divider="#00000000"
        android:fadingEdge="none"
        android:fadingEdgeLength="0px"
        android:listSelector="#00000000"
        pulltorefresh:type="chat" />
</RelativeLayout>

我在 AndroidManifest.xml 中添加了 AdjustPan 选项:

<activity
    android:name=".ui.ChatActivity"
    android:screenOrientation="portrait"
    android:windowSoftInputMode="stateHidden|adjustPan" >
</activity>

我猜,AdjustResize 在我的实现中不起作用,因为其中没有滚动视图。

打开软键盘时,调整聊天页面大小/调整聊天页面的最佳方式是什么?据我所知,也没有在 Android 中听键盘的实现。我只看到了一些与 global layoutlistener 相关的示例来了解键盘位置,但它对我来说效果不佳。

为什么 adjustpan 选项会隐藏我的操作栏,而不仅仅是聊天屏幕?

【问题讨论】:

  • 在清单中尝试 android:configChanges="orientation|keyboardHidden" 权限
  • 你在 Logcat 上得到什么了吗??
  • 添加您的建议后,我没有在 Logcat 上看到任何特定的日志/错误
  • 您使用的是自己的键盘还是提供的系统?
  • 执行此操作:在 com.handmark.pulltorefresh.library.PullToRefreshListView 设计中再添加一行 android:layout_weight="1" 并将 android:windowSoftInputMode="stateHidden|adjustPan" 更改为 android:windowSoftInputMode="只有adjustPan"...之后请告诉我

标签: android android-layout android-softkeyboard


【解决方案1】:

添加到 chat.xml 布局中的 pulltorefreshlistview:

android:transcriptMode="alwaysScroll"

它解决了一切。如果聊天列表视图在任何情况下都可以滚动,则无需侦听键盘事件即可手动滚动列表视图。

希望它对我以外的任何人都有帮助..

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多