Переглянути джерело

作业执行页锁定站item适配缩放

Frankensteinly 9 місяців тому
батько
коміт
05a6c4178f

+ 10 - 1
app/src/main/java/com/grkj/iscs/view/fragment/StepFragment.kt

@@ -2,6 +2,8 @@ package com.grkj.iscs.view.fragment
 
 import android.view.View
 import android.widget.ImageView
+import androidx.constraintlayout.widget.ConstraintLayout
+import androidx.recyclerview.widget.GridLayoutManager
 import com.bumptech.glide.Glide
 import com.google.android.material.card.MaterialCardView
 import com.grkj.iscs.R
@@ -79,9 +81,14 @@ class StepFragment(val goBack: () -> Unit, val changePage: (PageChangeBO) -> Uni
                 }
             }
         }
-
+        
         mBinding?.rvLoto?.adapter = object : CommonAdapter<LotoMapRespVO>(requireContext(), R.layout.item_rv_loto, mLotoList) {
             override fun convert(holder: ViewHolder, loto: LotoMapRespVO, position: Int) {
+                val cl = holder.getView<ConstraintLayout>(R.id.cl_container)
+                val param = cl.layoutParams
+                param.width = param.width * 3 / (mBinding?.rvLoto?.layoutManager as GridLayoutManager).spanCount
+                cl.layoutParams = param
+
                 Glide.with(this@StepFragment).load(loto.pointIcon).into(holder.getView(R.id.iv_icon))
                 holder.setText(R.id.tv_name, loto.pointName)
                 holder.setVisible(R.id.rl_cover, mMachineryDetail?.pointIdList?.contains(loto.pointId!!) == true)
@@ -155,6 +162,8 @@ class StepFragment(val goBack: () -> Unit, val changePage: (PageChangeBO) -> Uni
                 mLotoList.clear()
                 mLotoList.addAll(it)
             } ?: mLotoList.clear()
+            (mBinding?.rvLoto?.layoutManager as GridLayoutManager).spanCount =
+                if (mLotoList.size == 0) 3 else mLotoList.size / 3 + if (mLotoList.size % 3 == 0) 0 else 1
             mBinding?.rvLoto?.adapter?.notifyDataSetChanged()
         }
     }

+ 2 - 2
app/src/main/res/layout/fragment_step.xml

@@ -130,10 +130,10 @@
                 <androidx.recyclerview.widget.RecyclerView
                     android:id="@+id/rv_loto"
                     style="@style/CommonRecyclerView"
-                    android:layout_marginHorizontal="@dimen/common_spacing"
+                    android:layout_marginHorizontal="20dp"
                     android:layout_marginVertical="@dimen/common_spacing_small"
                     android:background="@mipmap/cabinet_small"
-                    android:paddingHorizontal="14dp"
+                    android:paddingHorizontal="@dimen/common_spacing"
                     android:paddingTop="10dp"
                     android:paddingBottom="12dp"
                     app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"

+ 61 - 25
app/src/main/res/layout/item_rv_loto.xml

@@ -1,39 +1,75 @@
 <?xml version="1.0" encoding="utf-8"?>
-<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
     android:id="@+id/root"
-    android:layout_width="15dp"
-    android:layout_height="18dp"
+    android:layout_width="wrap_content"
+    android:layout_height="wrap_content"
     android:layout_margin="@dimen/divider_line_width">
 
-    <LinearLayout
-        android:layout_width="match_parent"
-        android:layout_height="match_parent"
-        android:background="@drawable/item_rv_loto_bg"
-        android:gravity="center"
-        android:orientation="vertical">
+    <androidx.constraintlayout.widget.ConstraintLayout
+        android:id="@+id/cl_container"
+        android:layout_width="10dp"
+        android:layout_height="0dp"
+        android:background="@mipmap/red_stroke_bg"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintDimensionRatio="9:12"
+        app:layout_constraintLeft_toLeftOf="parent"
+        app:layout_constraintRight_toRightOf="parent"
+        app:layout_constraintTop_toTopOf="parent">
 
         <ImageView
             android:id="@+id/iv_icon"
-            android:layout_width="10dp"
-            android:layout_height="10dp" />
+            android:layout_width="0dp"
+            android:layout_height="0dp"
+            app:layout_constraintBottom_toBottomOf="parent"
+            app:layout_constraintDimensionRatio="1"
+            app:layout_constraintLeft_toLeftOf="parent"
+            app:layout_constraintRight_toRightOf="parent"
+            app:layout_constraintTop_toTopOf="parent"
+            app:layout_constraintVertical_bias="0.2"
+            app:layout_constraintWidth_percent="0.85" />
 
         <TextView
             android:id="@+id/tv_name"
             style="@style/CommonTextView"
             android:textColor="@color/lock_status_locked"
-            android:textSize="4dp" />
-    </LinearLayout>
+            android:textSize="4dp"
+            app:layout_constraintBottom_toBottomOf="parent"
+            app:layout_constraintLeft_toLeftOf="parent"
+            app:layout_constraintRight_toRightOf="parent"
+            app:layout_constraintTop_toTopOf="parent"
+            app:layout_constraintVertical_bias="0.85"
+            android:autoSizeTextType="uniform"
+            android:autoSizeStepGranularity="1dp"
+            android:autoSizeMinTextSize="2dp"
+            android:autoSizeMaxTextSize="20dp"/>
 
-    <RelativeLayout
-        android:id="@+id/rl_cover"
-        android:layout_width="match_parent"
-        android:layout_height="match_parent"
-        android:background="@drawable/item_rv_loto_cover_bg"
-        android:visibility="gone">
+        <androidx.constraintlayout.widget.ConstraintLayout
+            android:id="@+id/rl_cover"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent"
+            android:background="@color/common_bg_black_30"
+            android:visibility="gone"
+            app:layout_constraintBottom_toBottomOf="parent"
+            app:layout_constraintLeft_toLeftOf="parent"
+            app:layout_constraintRight_toRightOf="parent"
+            app:layout_constraintTop_toTopOf="parent">
 
-        <TextView
-            style="@style/CommonTextView"
-            android:layout_centerInParent="true"
-            android:text="√" />
-    </RelativeLayout>
-</RelativeLayout>
+            <TextView
+                android:id="@+id/tv_select"
+                style="@style/CommonTextView"
+                android:text="√"
+                android:textSize="8dp"
+                app:layout_constraintBottom_toBottomOf="parent"
+                app:layout_constraintLeft_toLeftOf="parent"
+                app:layout_constraintRight_toRightOf="parent"
+                app:layout_constraintTop_toTopOf="parent"
+                android:autoSizeTextType="uniform"
+                android:autoSizeStepGranularity="1dp"
+                android:autoSizeMinTextSize="1dp"
+                android:autoSizeMaxTextSize="20dp"/>
+        </androidx.constraintlayout.widget.ConstraintLayout>
+    </androidx.constraintlayout.widget.ConstraintLayout>
+
+
+</androidx.constraintlayout.widget.ConstraintLayout>

BIN
app/src/main/res/mipmap/red_stroke_bg.png