2016-10-11 83 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