私はRecyclerView
とEditText
をCardView
の内部に持っています。アクティビティの目的はチャットです。したがって、RecyclerView
には送受信されたすべてのメッセージが含まれ、CardView
にはユーザーがメッセージを入力する場所が含まれます。問題になると、キーボードがポップアップすると内容を上に移動する必要があります。さて、これは単純な問題ではないようです。キーボードがポップアップしたときに表示の内容をプッシュする方法は?
私はすべてのこれらの質問を試みた:
- Push up content when clicking in edit text
- How to move the layout up when the soft keyboard is shown android
- Move layouts up when soft keyboard is shown?
をそして、ほとんどの解決策は、android:windowSoftInputMode
を変更することに帰着します。私が試したところ、adjustPan
とadjustResize
に切り替えました。ここに私の活動へのコードは次のとおりです。
<?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-2
ActionBar
を
- を上昇させる:
は今、明らかに画像-1と画像2から、いくつかの問題があります。
は、任意のメソッドをオーバーライドして、物事を実装することが手動で可能です:キーボードが持ち上がったら
- は、トランジションアニメーション
- が追加されますそれはそう、質問があるまで
全体RecyclerViewをプッシュandroid:windowSoftInputMode
が好きなように変更することを許可する以外に、親切に助けてください。
adjustPan|adjustResize
はほとんど何も変更を加えないことを確認します。 @鉄人 – OBX