问题
I've a problem exactly like this LINK, same situation and same components in layouts. The only difference is the toolbar, but obviously i'm using appcompat and the behaviour is the same.
Attention, not only the toolbar is hided, but also the upper part of the recyclerview. Is like if the entire fragment is translated up when the softkeyboard is visible.
I'm using a toolbar like this in the main.xml of my activity:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<include layout="@layout/toolbar" />
<FrameLayout
android:id="@+id/container_root"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
Tha framelayout is replaced with this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical"
tools:ignore="MergeRootFrame" >
<!--<include layout="@layout/toolbar" />-->
<com.astuetz.PagerSlidingTabStrip
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="@color/primary"
android:textColor="#FFFFFF"
app:pstsIndicatorColor="#FFFFFF"
app:pstsPaddingMiddle="true"
android:maxHeight="20dp"
android:elevation="5dp"
/>
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
And inside the view pager i've a tab with this fragment's layout with the recyclerview:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerViewChat"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="50dip"/>
<EditText
android:id="@+id/txtChatLine"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="@string/txt_hint"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_toStartOf="@+id/button1">
</EditText>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/btn_send"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
When i start to enter text in the edittext the entire layout goes up, the toolbar become invisible (out of the screen) and the recyclerview doesn't scroll, but it's move up.
回答1:
I just had the same problem and @drakeet solution worked for me: RecyclerView hides Actionbar when SoftKeyboard is opened
I included an empty ScrollView between the Toolbar and the RecyclerView and the Toolbar stopped hiding.
<include android:id="@+id/app_bar" layout="@layout/toolbar"/>
<!--Empty ScrollView needed so the recyclerview doesn't hide the toolbar-->
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
</ScrollView>
<view
android:id="@+id/recycler_view"
android:layout_below="@id/app_bar"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="android.support.v7.widget.RecyclerView"
android:layout_above="@+id/message_layout"/>
回答2:
remove android:windowSoftInputMode="adjustPan"
from your AndroidManifest.xml
来源:https://stackoverflow.com/questions/28529474/recyclerview-hides-toolbar-and-layout-when-softkeyboard-is-visible