优化UI
This commit is contained in:
@@ -1,12 +1,17 @@
|
||||
package com.example.defenseapplication.home
|
||||
|
||||
import android.graphics.Color
|
||||
import android.graphics.Rect
|
||||
import android.graphics.drawable.GradientDrawable
|
||||
import android.os.Bundle
|
||||
import android.util.TypedValue
|
||||
import androidx.fragment.app.Fragment
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.example.defenseapplication.adapter.DeviceAdapter
|
||||
import com.example.defenseapplication.adapter.DeviceUi
|
||||
import com.example.defenseapplication.adapter.FamilyAdapter
|
||||
@@ -49,6 +54,17 @@ class HomeMenuFragment : Fragment() {
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
// 为 LinearLayout 设置渐变背景
|
||||
setGradientBackground(
|
||||
view = binding.gradientLayout,
|
||||
startColor = Color.parseColor("#EBDCED"),
|
||||
endColor = Color.parseColor("#CAF4FF")
|
||||
)
|
||||
}
|
||||
|
||||
private fun initView() {
|
||||
binding.rvFamilyList.layoutManager = LinearLayoutManager(requireContext())
|
||||
binding.rvFamilyList.adapter = familyAdapter
|
||||
@@ -56,6 +72,11 @@ class HomeMenuFragment : Fragment() {
|
||||
|
||||
binding.rvDeviceList.layoutManager = GridLayoutManager(requireContext(), 2)
|
||||
binding.rvDeviceList.adapter = deviceAdapter
|
||||
if (binding.rvDeviceList.itemDecorationCount == 0) {
|
||||
binding.rvDeviceList.addItemDecoration(
|
||||
GridHorizontalSpaceItemDecoration(horizontalSpace = dpToPx(8))
|
||||
)
|
||||
}
|
||||
updateDeviceList()
|
||||
|
||||
binding.tvCurrentFamily.text = currentFamily
|
||||
@@ -94,6 +115,45 @@ class HomeMenuFragment : Fragment() {
|
||||
deviceAdapter.submitList(familyDeviceMap[currentFamily].orEmpty())
|
||||
}
|
||||
|
||||
private fun dpToPx(dp: Int): Int {
|
||||
return TypedValue.applyDimension(
|
||||
TypedValue.COMPLEX_UNIT_DIP,
|
||||
dp.toFloat(),
|
||||
resources.displayMetrics
|
||||
).toInt()
|
||||
}
|
||||
|
||||
private class GridHorizontalSpaceItemDecoration(
|
||||
private val horizontalSpace: Int
|
||||
) : RecyclerView.ItemDecoration() {
|
||||
override fun getItemOffsets(
|
||||
outRect: Rect,
|
||||
view: View,
|
||||
parent: RecyclerView,
|
||||
state: RecyclerView.State
|
||||
) {
|
||||
val position = parent.getChildAdapterPosition(view)
|
||||
if (position == RecyclerView.NO_POSITION) return
|
||||
|
||||
if (position % 2 == 0) {
|
||||
outRect.right = horizontalSpace / 2
|
||||
} else {
|
||||
outRect.left = horizontalSpace / 2
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun setGradientBackground(
|
||||
view: View,
|
||||
startColor: Int,
|
||||
endColor: Int,
|
||||
orientation: GradientDrawable.Orientation = GradientDrawable.Orientation.TL_BR
|
||||
) {
|
||||
val gradientDrawable = GradientDrawable(orientation, intArrayOf(startColor, endColor))
|
||||
gradientDrawable.gradientType = GradientDrawable.LINEAR_GRADIENT
|
||||
view.background = gradientDrawable
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
binding.rvFamilyList.adapter = null
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.example.defenseapplication.login
|
||||
|
||||
import android.graphics.Color
|
||||
import android.graphics.drawable.GradientDrawable
|
||||
import android.os.Bundle
|
||||
import android.os.CountDownTimer
|
||||
import android.text.InputType
|
||||
@@ -32,7 +34,10 @@ class ForgetPasswordActivity : AppCompatActivity() {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = ForgetPasswordActivityBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
// 设置渐变背景
|
||||
val startColor = Color.parseColor("#CBEBFA")
|
||||
val endColor = Color.parseColor("#FFF2EF")
|
||||
setGradientBackground(binding.main, startColor, endColor)
|
||||
setupClickListeners()
|
||||
}
|
||||
|
||||
@@ -168,6 +173,16 @@ class ForgetPasswordActivity : AppCompatActivity() {
|
||||
|
||||
|
||||
}
|
||||
private fun setGradientBackground(
|
||||
view: android.view.View,
|
||||
startColor: Int,
|
||||
endColor: Int,
|
||||
orientation: GradientDrawable.Orientation = GradientDrawable.Orientation.TL_BR
|
||||
) {
|
||||
val gradientDrawable = GradientDrawable(orientation, intArrayOf(startColor, endColor))
|
||||
gradientDrawable.gradientType = GradientDrawable.LINEAR_GRADIENT
|
||||
view.background = gradientDrawable
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.example.defenseapplication.login
|
||||
import android.content.Intent
|
||||
import android.graphics.Color
|
||||
import android.graphics.drawable.GradientDrawable
|
||||
import com.example.defenseapplication.R
|
||||
import android.os.Bundle
|
||||
import android.os.CountDownTimer
|
||||
@@ -22,6 +24,11 @@ class LoginActivity : AppCompatActivity() {
|
||||
binding = ActivityLoginBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
// 设置渐变背景
|
||||
val startColor = Color.parseColor("#CBEBFA")
|
||||
val endColor = Color.parseColor("#FFF2EF")
|
||||
setGradientBackground(binding.main, startColor, endColor)
|
||||
|
||||
setupTabListeners()
|
||||
setupClickListeners()
|
||||
switchToSmsMode()
|
||||
@@ -159,4 +166,15 @@ class LoginActivity : AppCompatActivity() {
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
|
||||
private fun setGradientBackground(
|
||||
view: android.view.View,
|
||||
startColor: Int,
|
||||
endColor: Int,
|
||||
orientation: GradientDrawable.Orientation = GradientDrawable.Orientation.TL_BR
|
||||
) {
|
||||
val gradientDrawable = GradientDrawable(orientation, intArrayOf(startColor, endColor))
|
||||
gradientDrawable.gradientType = GradientDrawable.LINEAR_GRADIENT
|
||||
view.background = gradientDrawable
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.example.defenseapplication.login
|
||||
|
||||
import android.content.Intent
|
||||
import android.graphics.Color
|
||||
import android.graphics.drawable.GradientDrawable
|
||||
import android.os.Bundle
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
@@ -19,7 +21,10 @@ class RegisterActivity : AppCompatActivity() {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = RegisterActivityBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
// 设置渐变背景
|
||||
val startColor = Color.parseColor("#CBEBFA")
|
||||
val endColor = Color.parseColor("#FFF2EF")
|
||||
setGradientBackground(binding.main, startColor, endColor)
|
||||
setupListeners()
|
||||
//setupTextWatchers()
|
||||
}
|
||||
@@ -187,4 +192,14 @@ class RegisterActivity : AppCompatActivity() {
|
||||
// private fun validatePassword(password: String): Boolean {
|
||||
// return password.length in 6..20
|
||||
// }
|
||||
private fun setGradientBackground(
|
||||
view: android.view.View,
|
||||
startColor: Int,
|
||||
endColor: Int,
|
||||
orientation: GradientDrawable.Orientation = GradientDrawable.Orientation.TL_BR
|
||||
) {
|
||||
val gradientDrawable = GradientDrawable(orientation, intArrayOf(startColor, endColor))
|
||||
gradientDrawable.gradientType = GradientDrawable.LINEAR_GRADIENT
|
||||
view.background = gradientDrawable
|
||||
}
|
||||
}
|
||||
@@ -220,7 +220,7 @@
|
||||
android:id="@+id/loginBtn"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="32dp"
|
||||
android:layout_marginTop="40dp"
|
||||
android:text="登录"
|
||||
android:textSize="18sp"
|
||||
android:background="@drawable/rounded_blue_bg"
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
android:id="@+id/fragment_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:background="#F5F6F6"
|
||||
app:layout_constraintBottom_toTopOf="@id/bottom_layout"
|
||||
app:layout_constraintTop_toTopOf="parent"/>
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#F9F9F9 "
|
||||
tools:context=".home.HomeMenuFragment">
|
||||
|
||||
<LinearLayout
|
||||
@@ -12,6 +11,7 @@
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/gradient_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
@@ -101,25 +101,22 @@
|
||||
</FrameLayout>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvDeviceTitle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="14dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:text="设备"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="16dp"
|
||||
android:textStyle="bold" />
|
||||
</LinearLayout>
|
||||
|
||||
<GridLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:columnCount="2"
|
||||
android:orientation="vertical"
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<androidx.constraintlayout.widget.ConstraintLayout 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:background="@color/login_background"
|
||||
android:background="@color/white"
|
||||
android:id="@+id/main"
|
||||
android:padding="16dp"
|
||||
android:layout_width="match_parent"
|
||||
|
||||
Reference in New Issue
Block a user