Browse Source

聊天界面微调

徐勤民 3 months ago
parent
commit
967cc87508

+ 11 - 9
app/src/main/java/com/xuqinmin/android/app/ui/ChatActivity.kt

@@ -8,6 +8,7 @@ import android.widget.ImageView
 import android.widget.LinearLayout
 import android.widget.TextView
 import androidx.activity.viewModels
+import androidx.constraintlayout.widget.ConstraintLayout
 import com.gyf.immersionbar.BarHide
 import com.gyf.immersionbar.ImmersionBar
 import com.luck.picture.lib.basic.PictureSelector
@@ -203,20 +204,21 @@ class ChatActivity : BaseActivity<ActivityChatBinding>() {
 
         window.decorView.viewTreeObserver.addOnGlobalLayoutListener {
             val r = Rect()
-            window.decorView.getWindowVisibleDisplayFrame(r);
-            val screenHeight = window.decorView.rootView.height;
-            val keypadHeight = screenHeight - r.bottom;
+            window.decorView.getWindowVisibleDisplayFrame(r)
+            val screenHeight = window.decorView.rootView.height
+            val keypadHeight = screenHeight - r.bottom
 
             if (keypadHeight > screenHeight * 0.15) {
                 // 输入法弹出
-                val params = binding.bto.layoutParams as LinearLayout.LayoutParams
-                params.height = keypadHeight;
-                binding.bto.layoutParams = params
+                val params = binding.view.layoutParams as ConstraintLayout.LayoutParams
+                params.height = keypadHeight
+                binding.view.layoutParams = params
+                binding.baseRecyclerView.scrollToPosition(listMsg.size - 1)
             } else {
                 // 输入法隐藏
-                val params = binding.bto.layoutParams as LinearLayout.LayoutParams
-                params.height = 0;
-                binding.bto.layoutParams = params
+                val params = binding.view.layoutParams as ConstraintLayout.LayoutParams
+                params.height = 1
+                binding.view.layoutParams = params
             }
         }
     }

+ 36 - 27
app/src/main/res/layout/activity_chat.xml

@@ -1,9 +1,9 @@
 <?xml version="1.0" encoding="utf-8"?>
 <layout xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:app="http://schemas.android.com/apk/res-auto">
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    xmlns:tools="http://schemas.android.com/tools">
 
-    <LinearLayout
-        android:orientation="vertical"
+    <androidx.constraintlayout.widget.ConstraintLayout
         android:layout_width="match_parent"
         android:layout_height="match_parent">
 
@@ -72,9 +72,9 @@
         <androidx.constraintlayout.widget.ConstraintLayout
             android:id="@+id/empty"
             android:layout_width="match_parent"
-            android:layout_height="0dp"
-            android:layout_weight="1"
-            android:visibility="gone">
+            android:layout_height="wrap_content"
+            android:visibility="visible"
+            app:layout_constraintTop_toBottomOf="@+id/top">
 
             <ImageView
                 android:id="@+id/head"
@@ -150,10 +150,12 @@
             android:layout_width="345dp"
             android:layout_height="145dp"
             android:layout_marginTop="-14dp"
-            android:layout_gravity="center_horizontal"
             android:background="@drawable/bg_tag_match"
             android:padding="15dp"
-            android:visibility="visible">
+            android:visibility="gone"
+            app:layout_constraintEnd_toEndOf="parent"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintTop_toBottomOf="@+id/top">
 
             <ImageView
                 android:id="@+id/avatar3"
@@ -240,27 +242,22 @@
                 app:layout_constraintTop_toBottomOf="@+id/line" />
         </androidx.constraintlayout.widget.ConstraintLayout>
 
-        <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
-            android:id="@+id/baseRefreshLayout"
+        <View
+            android:id="@+id/view"
             android:layout_width="match_parent"
-            android:layout_height="0dp"
-            android:paddingTop="3dp"
-            android:layout_weight="1"
-            android:visibility="visible">
+            android:layout_height="1dp"
+            android:visibility="visible"
+            android:background="@color/white"
+            app:layout_constraintBottom_toBottomOf="parent" />
 
-            <androidx.recyclerview.widget.RecyclerView
-                android:id="@+id/baseRecyclerView"
-                android:layout_width="match_parent"
-                android:layout_weight="2"
-                android:layout_height="0dp"
-                android:overScrollMode="never" />
-        </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
         <androidx.constraintlayout.widget.ConstraintLayout
             android:id="@+id/toolbar"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:minHeight="80dp"
-            android:paddingVertical="16dp">
+            android:background="@color/white"
+            android:paddingVertical="16dp"
+            app:layout_constraintBottom_toTopOf="@+id/view">
 
             <ImageView
                 android:id="@+id/send_pic"
@@ -304,7 +301,6 @@
                     android:layout_marginEnd="10dp"
                     android:background="@null"
                     android:maxLines="3"
-                    android:layout_weight="1"
                     android:minHeight="30dp"
                     android:textColor="#ff222222"
                     android:textSize="14sp"
@@ -321,11 +317,24 @@
                     app:layout_constraintTop_toTopOf="parent" />
             </LinearLayout>
         </androidx.constraintlayout.widget.ConstraintLayout>
-        <View
-            android:id="@+id/bto"
+
+        <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
+            android:id="@+id/baseRefreshLayout"
             android:layout_width="match_parent"
-            android:layout_height="0dp"/>
+            android:layout_height="0dp"
+            android:layout_marginTop="3dp"
+            android:visibility="gone"
+            app:layout_constraintBottom_toTopOf="@+id/toolbar"
+            app:layout_constraintEnd_toEndOf="parent"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintTop_toBottomOf="@+id/chat_top">
 
+            <androidx.recyclerview.widget.RecyclerView
+                android:id="@+id/baseRecyclerView"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"
+                android:overScrollMode="never" />
+        </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
 
-    </LinearLayout>
+    </androidx.constraintlayout.widget.ConstraintLayout>
 </layout>