2016-10-11 84 views
2

我在CardView內有RecyclerViewEditText。該活動的目的是聊天。因此RecyclerView包含所有發送和接收的消息,並且CardView是用戶輸入消息的地方。出現問題時,我需要在彈出鍵盤時將內容向上移動。現在,這似乎不是一個簡單的問題。如何在彈出鍵盤時將視圖的內容向上推?

我嘗試了所有這些問題:

而且,解決最歸結爲改變android:windowSoftInputMode。我嘗試過,切換到adjustPanadjustResize。下面是代碼到我的活動:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#F0F0F0" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:paddingStart="10dp" 
    android:paddingEnd="10dp" 
    tools:context="com.devpost.airway.MainActivity"> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/chatView" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 
    </android.support.v7.widget.RecyclerView> 

    <android.support.v7.widget.CardView 
     android:layout_alignParentBottom="true" 
     android:layout_marginTop="10dp" 
     app:cardElevation="0dp" 
     app:cardCornerRadius="10dp" 
     android:layout_marginBottom="10dp" 
     android:layout_width="match_parent" 
     android:layout_height="50dp"> 

     <EditText 
      android:id="@+id/chat_input" 
      android:paddingStart="2dp" 
      android:paddingEnd="2dp" 
      android:inputType="text" 
      android:imeOptions="actionSend" 
      android:background="@null" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 
    </android.support.v7.widget.CardView> 

</RelativeLayout> 

而且adjustPan確實在一個非常模糊的方式工作,我已經添加下面的截圖,請看看:

IMAGE-1

IMAGE-1

IMAGE-2

enter image description here

現在,顯然從圖片-1和圖像2中,有幾個問題:

  • ActionBar向上移動。
  • 當鍵盤彈出它增加了一個過渡動畫
  • 它推動了整個RecyclerView了

所以,問題是:

手動是否可以覆蓋任何方法和實施的事情我自己,除了允許android:windowSoftInputMode改變它喜歡的方式?請幫助。

+0

幾乎沒有進行任何更改,不會做任何事情。 @鋼鐵俠 – OBX

回答

-1
<android.support.v7.widget.RecyclerView 
    android:id="@+id/chatView" 
    android:layout_width="match_parent" 
    android:layout_above="@+id/editorCard" 
    android:layout_height="wrap_content" /> 

<android.support.v7.widget.CardView 
    android:id="@+id/editorCard" 
    android:layout_alignParentBottom="true" 
    android:layout_marginTop="10dp" 
    app:cardElevation="0dp" 
    app:cardCornerRadius="10dp" 
    android:layout_marginBottom="10dp" 
    android:layout_width="match_parent" 
    android:layout_height="50dp"> 
<!--your editor code--> 
</android.support.v7.widget.CardView> 

wrap_contentlayout_above是所期望的行爲

softinputmethod重要變更,使其adjustPan|adjustResize