Android软键盘隐藏RecyclerView
Android soft keyboard hides RecyclerView
我正在尝试制作一个 comments/chat 布局,底部有一个 RecyclerView
和一个固定的 EditText
。请不要说 adjustPan
或 adjustResize
。不起作用。 adjustPan
隐藏键盘。
我真的需要帮助,这真令人沮丧
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/appbarlayout"
android:paddingTop="@dimen/app_bar_top_padding">
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:theme="@style/ThemeOverlay.AppCompat.ActionBar"
android:id="@+id/toolbar"
app:titleTextColor="#FFFFFF" />
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/recycler_view"
android:layout_below="@+id/appbarlayout"
android:isScrollContainer="false"
android:stackFromBottom="true"
android:transcriptMode="normal"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#2b2b2b"
android:orientation="vertical"
android:id="@+id/chat_box"
android:layout_alignParentBottom="true">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?android:attr/listDivider"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Skriv en kommentar"
android:background="@android:color/transparent"
android:textColor="@color/white"
android:textColorHint="#d4d4d4"
android:inputType="textCapSentences|textMultiLine"
android:layout_marginRight="40dp"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_send"
android:background="@drawable/click"
android:layout_gravity="right|center_vertical" />
</FrameLayout>
</LinearLayout>
</RelativeLayout>
正确答案是 adjustResize,因此应用会在键盘上方调整大小。然而,为了让它工作,您的布局的其余部分需要编写为可调整大小。你的不是,因为回收站视图没有固定到位。在其上添加 layout_above="@+id/chatBox"
约束,使其位于编辑文本上方,并且应调整大小以正确适应 space。
此外,adjustPan 不会隐藏键盘。如果是这样,那么您的代码确实有问题。 adjustPan 在不调整大小的情况下向上滑动您的应用程序。这可能是您想要的,如果您能找出您的应用程序中隐藏键盘的内容。
不知道为什么,但 Gabe Sechan 给出的解决方案对我不起作用。对我有用的是将其添加到清单文件中。
android:windowSoftInputMode="adjustPan"
我正在尝试制作一个 comments/chat 布局,底部有一个 RecyclerView
和一个固定的 EditText
。请不要说 adjustPan
或 adjustResize
。不起作用。 adjustPan
隐藏键盘。
我真的需要帮助,这真令人沮丧
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/appbarlayout"
android:paddingTop="@dimen/app_bar_top_padding">
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:theme="@style/ThemeOverlay.AppCompat.ActionBar"
android:id="@+id/toolbar"
app:titleTextColor="#FFFFFF" />
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/recycler_view"
android:layout_below="@+id/appbarlayout"
android:isScrollContainer="false"
android:stackFromBottom="true"
android:transcriptMode="normal"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#2b2b2b"
android:orientation="vertical"
android:id="@+id/chat_box"
android:layout_alignParentBottom="true">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?android:attr/listDivider"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Skriv en kommentar"
android:background="@android:color/transparent"
android:textColor="@color/white"
android:textColorHint="#d4d4d4"
android:inputType="textCapSentences|textMultiLine"
android:layout_marginRight="40dp"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_send"
android:background="@drawable/click"
android:layout_gravity="right|center_vertical" />
</FrameLayout>
</LinearLayout>
</RelativeLayout>
正确答案是 adjustResize,因此应用会在键盘上方调整大小。然而,为了让它工作,您的布局的其余部分需要编写为可调整大小。你的不是,因为回收站视图没有固定到位。在其上添加 layout_above="@+id/chatBox"
约束,使其位于编辑文本上方,并且应调整大小以正确适应 space。
此外,adjustPan 不会隐藏键盘。如果是这样,那么您的代码确实有问题。 adjustPan 在不调整大小的情况下向上滑动您的应用程序。这可能是您想要的,如果您能找出您的应用程序中隐藏键盘的内容。
不知道为什么,但 Gabe Sechan 给出的解决方案对我不起作用。对我有用的是将其添加到清单文件中。
android:windowSoftInputMode="adjustPan"