feat: opt 出港计重 开始计重 floatButton
This commit is contained in:
@@ -1,8 +1,13 @@
|
||||
package com.lukouguoji.gjc.activity
|
||||
|
||||
import android.animation.Animator
|
||||
import android.animation.AnimatorListenerAdapter
|
||||
import android.animation.AnimatorSet
|
||||
import android.animation.ObjectAnimator
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import com.alibaba.android.arouter.facade.annotation.Route
|
||||
import com.lukouguoji.gjc.R
|
||||
import com.lukouguoji.gjc.databinding.ActivityGjcWeighingStartBinding
|
||||
@@ -18,6 +23,8 @@ import com.lukouguoji.module_base.router.ARouterConstants
|
||||
class GjcWeighingStartActivity :
|
||||
BaseBindingActivity<ActivityGjcWeighingStartBinding, GjcWeighingStartViewModel>() {
|
||||
|
||||
private var isExpanded = false
|
||||
|
||||
override fun layoutId() = R.layout.activity_gjc_weighing_start
|
||||
|
||||
override fun viewModelClass() = GjcWeighingStartViewModel::class.java
|
||||
@@ -26,6 +33,153 @@ class GjcWeighingStartActivity :
|
||||
setBackArrow("开始计重")
|
||||
binding.viewModel = viewModel
|
||||
viewModel.initOnCreated(this, intent)
|
||||
|
||||
setupFloatButtons()
|
||||
}
|
||||
|
||||
private fun setupFloatButtons() {
|
||||
// 主按钮点击事件
|
||||
binding.mainFloatButton.setOnClickListener {
|
||||
if (!isExpanded) {
|
||||
expandButtons()
|
||||
}
|
||||
}
|
||||
|
||||
// 遮罩层点击事件
|
||||
binding.maskView.setOnClickListener {
|
||||
collapseButtons()
|
||||
}
|
||||
|
||||
// 子按钮1点击事件 - 跳转到出港运抵页面
|
||||
binding.subButton1.setOnClickListener {
|
||||
com.alibaba.android.arouter.launcher.ARouter.getInstance()
|
||||
.build(ARouterConstants.ACTIVITY_URL_INT_EXP_ARRIVE)
|
||||
.navigation()
|
||||
collapseButtons()
|
||||
}
|
||||
|
||||
// 子按钮2点击事件 - 跳转到计重记录
|
||||
binding.subButton2.setOnClickListener {
|
||||
com.alibaba.android.arouter.launcher.ARouter.getInstance()
|
||||
.build(ARouterConstants.ACTIVITY_URL_GJC_WEIGHING_RECORD_LIST)
|
||||
.navigation()
|
||||
collapseButtons()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 展开子按钮
|
||||
*/
|
||||
private fun expandButtons() {
|
||||
isExpanded = true
|
||||
|
||||
// 显示遮罩层
|
||||
binding.maskView.visibility = View.VISIBLE
|
||||
binding.maskView.alpha = 0f
|
||||
binding.maskView.animate().alpha(0.3f).setDuration(200).start()
|
||||
|
||||
// 显示子按钮
|
||||
binding.subButton1.visibility = View.VISIBLE
|
||||
binding.subButton2.visibility = View.VISIBLE
|
||||
|
||||
// 子按钮1动画(向左上方移动: 左移15dp, 上移55dp)
|
||||
val sub1TransX = ObjectAnimator.ofFloat(binding.subButton1, "translationX", 0f, -5f)
|
||||
val sub1TransY = ObjectAnimator.ofFloat(binding.subButton1, "translationY", 0f, -25f)
|
||||
val sub1Alpha = ObjectAnimator.ofFloat(binding.subButton1, "alpha", 0f, 1f)
|
||||
val sub1Scale = ObjectAnimator.ofFloat(binding.subButton1, "scaleX", 0f, 1f)
|
||||
val sub1ScaleY = ObjectAnimator.ofFloat(binding.subButton1, "scaleY", 0f, 1f)
|
||||
|
||||
val animSet1 = AnimatorSet()
|
||||
animSet1.playTogether(sub1TransX, sub1TransY, sub1Alpha, sub1Scale, sub1ScaleY)
|
||||
animSet1.duration = 200
|
||||
|
||||
// 子按钮2动画(向左下方移动: 左移55dp, 下移15dp)
|
||||
val sub2TransX = ObjectAnimator.ofFloat(binding.subButton2, "translationX", 0f, -25f)
|
||||
val sub2TransY = ObjectAnimator.ofFloat(binding.subButton2, "translationY", 0f, -5f)
|
||||
val sub2Alpha = ObjectAnimator.ofFloat(binding.subButton2, "alpha", 0f, 1f)
|
||||
val sub2Scale = ObjectAnimator.ofFloat(binding.subButton2, "scaleX", 0f, 1f)
|
||||
val sub2ScaleY = ObjectAnimator.ofFloat(binding.subButton2, "scaleY", 0f, 1f)
|
||||
|
||||
val animSet2 = AnimatorSet()
|
||||
animSet2.playTogether(sub2TransX, sub2TransY, sub2Alpha, sub2Scale, sub2ScaleY)
|
||||
animSet2.duration = 200
|
||||
animSet2.startDelay = 50
|
||||
|
||||
// 主按钮隐藏动画
|
||||
binding.mainFloatButton.animate()
|
||||
.scaleX(0f)
|
||||
.scaleY(0f)
|
||||
.alpha(0f)
|
||||
.setDuration(150)
|
||||
.setListener(object : AnimatorListenerAdapter() {
|
||||
override fun onAnimationEnd(animation: Animator) {
|
||||
binding.mainFloatButton.visibility = View.GONE
|
||||
}
|
||||
})
|
||||
.start()
|
||||
|
||||
animSet1.start()
|
||||
animSet2.start()
|
||||
}
|
||||
|
||||
/**
|
||||
* 收起子按钮
|
||||
*/
|
||||
private fun collapseButtons() {
|
||||
isExpanded = false
|
||||
|
||||
// 隐藏遮罩层
|
||||
binding.maskView.animate().alpha(0f).setDuration(200).withEndAction {
|
||||
binding.maskView.visibility = View.GONE
|
||||
}.start()
|
||||
|
||||
// 子按钮1动画(回到原位)
|
||||
val sub1TransX = ObjectAnimator.ofFloat(binding.subButton1, "translationX", binding.subButton1.translationX, 0f)
|
||||
val sub1TransY = ObjectAnimator.ofFloat(binding.subButton1, "translationY", binding.subButton1.translationY, 0f)
|
||||
val sub1Alpha = ObjectAnimator.ofFloat(binding.subButton1, "alpha", 1f, 0f)
|
||||
val sub1Scale = ObjectAnimator.ofFloat(binding.subButton1, "scaleX", 1f, 0f)
|
||||
val sub1ScaleY = ObjectAnimator.ofFloat(binding.subButton1, "scaleY", 1f, 0f)
|
||||
|
||||
val animSet1 = AnimatorSet()
|
||||
animSet1.playTogether(sub1TransX, sub1TransY, sub1Alpha, sub1Scale, sub1ScaleY)
|
||||
animSet1.duration = 200
|
||||
|
||||
// 子按钮2动画(回到原位)
|
||||
val sub2TransX = ObjectAnimator.ofFloat(binding.subButton2, "translationX", binding.subButton2.translationX, 0f)
|
||||
val sub2TransY = ObjectAnimator.ofFloat(binding.subButton2, "translationY", binding.subButton2.translationY, 0f)
|
||||
val sub2Alpha = ObjectAnimator.ofFloat(binding.subButton2, "alpha", 1f, 0f)
|
||||
val sub2Scale = ObjectAnimator.ofFloat(binding.subButton2, "scaleX", 1f, 0f)
|
||||
val sub2ScaleY = ObjectAnimator.ofFloat(binding.subButton2, "scaleY", 1f, 0f)
|
||||
|
||||
val animSet2 = AnimatorSet()
|
||||
animSet2.playTogether(sub2TransX, sub2TransY, sub2Alpha, sub2Scale, sub2ScaleY)
|
||||
animSet2.duration = 200
|
||||
|
||||
animSet1.addListener(object : AnimatorListenerAdapter() {
|
||||
override fun onAnimationEnd(animation: Animator) {
|
||||
binding.subButton1.visibility = View.GONE
|
||||
}
|
||||
})
|
||||
|
||||
animSet2.addListener(object : AnimatorListenerAdapter() {
|
||||
override fun onAnimationEnd(animation: Animator) {
|
||||
binding.subButton2.visibility = View.GONE
|
||||
}
|
||||
})
|
||||
|
||||
// 主按钮显示动画
|
||||
binding.mainFloatButton.visibility = View.VISIBLE
|
||||
binding.mainFloatButton.animate()
|
||||
.scaleX(1f)
|
||||
.scaleY(1f)
|
||||
.alpha(1f)
|
||||
.setDuration(200)
|
||||
.setStartDelay(100)
|
||||
.setListener(null)
|
||||
.start()
|
||||
|
||||
animSet1.start()
|
||||
animSet2.start()
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
5
module_gjc/src/main/res/drawable/bg_float_button.xml
Normal file
5
module_gjc/src/main/res/drawable/bg_float_button.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="oval">
|
||||
<solid android:color="#699cf8" />
|
||||
</shape>
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 1.8 KiB |
@@ -11,19 +11,23 @@
|
||||
type="com.lukouguoji.gjc.viewModel.GjcWeighingStartViewModel" />
|
||||
</data>
|
||||
|
||||
<LinearLayout
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/color_f2"
|
||||
android:orientation="vertical">
|
||||
android:background="@color/color_f2">
|
||||
|
||||
<include layout="@layout/title_tool_bar" />
|
||||
|
||||
<!-- 主内容区域 -->
|
||||
<ScrollView
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1">
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<include layout="@layout/title_tool_bar" />
|
||||
|
||||
<!-- 主内容区域 -->
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
@@ -432,4 +436,46 @@
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<!-- 浮动按钮组 -->
|
||||
<!-- 遮罩层(点击收起) -->
|
||||
<View
|
||||
android:id="@+id/maskView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:visibility="gone" />
|
||||
|
||||
<!-- 子按钮1 -->
|
||||
<View
|
||||
android:id="@+id/subButton1"
|
||||
android:layout_width="44dp"
|
||||
android:layout_height="44dp"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:layout_marginEnd="25dp"
|
||||
android:layout_marginBottom="70dp"
|
||||
android:background="@drawable/bg_float_button"
|
||||
android:visibility="gone" />
|
||||
|
||||
<!-- 子按钮2 -->
|
||||
<View
|
||||
android:id="@+id/subButton2"
|
||||
android:layout_width="44dp"
|
||||
android:layout_height="44dp"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:layout_marginEnd="70dp"
|
||||
android:layout_marginBottom="25dp"
|
||||
android:background="@drawable/bg_float_button"
|
||||
android:visibility="gone" />
|
||||
|
||||
<!-- 主浮动按钮 -->
|
||||
<ImageView
|
||||
android:id="@+id/mainFloatButton"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:background="@drawable/ic_float_button_weighing_start" />
|
||||
|
||||
</FrameLayout>
|
||||
</layout>
|
||||
|
||||
Reference in New Issue
Block a user