fix: 状态栏固定在顶部,不随ViewPager2滑动
- 状态栏从两个子页面移到fragment_home.xml顶层 - ViewPager2在状态栏下方滑动 - HomeFragment只维护一个固定statusBar引用 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -39,8 +39,10 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>() {
|
|||||||
@Inject lateinit var eventBus: EventBus
|
@Inject lateinit var eventBus: EventBus
|
||||||
@Inject lateinit var taskApi: TaskApi
|
@Inject lateinit var taskApi: TaskApi
|
||||||
|
|
||||||
|
// ===== 固定状态栏(不随 ViewPager 滑动) =====
|
||||||
|
private lateinit var statusBar: StatusBarView
|
||||||
|
|
||||||
// ===== 主页 View 引用 =====
|
// ===== 主页 View 引用 =====
|
||||||
private lateinit var mainStatusBar: StatusBarView
|
|
||||||
private lateinit var tvClock: TextView
|
private lateinit var tvClock: TextView
|
||||||
private lateinit var tvDate: TextView
|
private lateinit var tvDate: TextView
|
||||||
private lateinit var tvPoolNum: TextView
|
private lateinit var tvPoolNum: TextView
|
||||||
@@ -48,7 +50,6 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>() {
|
|||||||
private lateinit var tvCompleteNum: TextView
|
private lateinit var tvCompleteNum: TextView
|
||||||
|
|
||||||
// ===== 设置页 View 引用 =====
|
// ===== 设置页 View 引用 =====
|
||||||
private lateinit var configStatusBar: StatusBarView
|
|
||||||
private lateinit var tvAvatarLetter: TextView
|
private lateinit var tvAvatarLetter: TextView
|
||||||
private lateinit var tvUserName: TextView
|
private lateinit var tvUserName: TextView
|
||||||
private lateinit var tvUserPhone: TextView
|
private lateinit var tvUserPhone: TextView
|
||||||
@@ -64,6 +65,9 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>() {
|
|||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
|
||||||
|
// 绑定固定状态栏(不随 ViewPager 滑动)
|
||||||
|
statusBar = binding.statusBar
|
||||||
|
|
||||||
// 创建两个页面 View
|
// 创建两个页面 View
|
||||||
val inflater = LayoutInflater.from(requireContext())
|
val inflater = LayoutInflater.from(requireContext())
|
||||||
val configPage = inflater.inflate(R.layout.page_config, null)
|
val configPage = inflater.inflate(R.layout.page_config, null)
|
||||||
@@ -96,7 +100,6 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>() {
|
|||||||
|
|
||||||
/** 绑定主页 View 引用 */
|
/** 绑定主页 View 引用 */
|
||||||
private fun bindMainViews(page: View) {
|
private fun bindMainViews(page: View) {
|
||||||
mainStatusBar = page.findViewById(R.id.statusBar)
|
|
||||||
tvClock = page.findViewById(R.id.tvClock)
|
tvClock = page.findViewById(R.id.tvClock)
|
||||||
tvDate = page.findViewById(R.id.tvDate)
|
tvDate = page.findViewById(R.id.tvDate)
|
||||||
tvPoolNum = page.findViewById(R.id.tvPoolNum)
|
tvPoolNum = page.findViewById(R.id.tvPoolNum)
|
||||||
@@ -161,7 +164,6 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>() {
|
|||||||
/** 绑定设置页 View 引用并直接填充数据 */
|
/** 绑定设置页 View 引用并直接填充数据 */
|
||||||
private fun bindConfigViews(page: View) {
|
private fun bindConfigViews(page: View) {
|
||||||
configPageView = page
|
configPageView = page
|
||||||
configStatusBar = page.findViewById(R.id.statusBar)
|
|
||||||
tvAvatarLetter = page.findViewById(R.id.tvAvatarLetter)
|
tvAvatarLetter = page.findViewById(R.id.tvAvatarLetter)
|
||||||
tvUserName = page.findViewById(R.id.tvUserName)
|
tvUserName = page.findViewById(R.id.tvUserName)
|
||||||
tvUserPhone = page.findViewById(R.id.tvUserPhone)
|
tvUserPhone = page.findViewById(R.id.tvUserPhone)
|
||||||
@@ -225,15 +227,13 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>() {
|
|||||||
viewLifecycleOwner.lifecycleScope.launch {
|
viewLifecycleOwner.lifecycleScope.launch {
|
||||||
eventBus.events.collect { event ->
|
eventBus.events.collect { event ->
|
||||||
when (event) {
|
when (event) {
|
||||||
// 电量变化:更新两个状态栏
|
// 电量变化:更新固定状态栏
|
||||||
is AppEvent.BatteryChanged -> {
|
is AppEvent.BatteryChanged -> {
|
||||||
mainStatusBar.updateBattery(event.level, event.isCharging)
|
statusBar.updateBattery(event.level, event.isCharging)
|
||||||
configStatusBar.updateBattery(event.level, event.isCharging)
|
|
||||||
}
|
}
|
||||||
// 蓝牙状态变化
|
// 蓝牙状态变化
|
||||||
is AppEvent.BluetoothStateChanged -> {
|
is AppEvent.BluetoothStateChanged -> {
|
||||||
mainStatusBar.updateBluetooth(event.isOn)
|
statusBar.updateBluetooth(event.isOn)
|
||||||
configStatusBar.updateBluetooth(event.isOn)
|
|
||||||
}
|
}
|
||||||
// MQTT 消息
|
// MQTT 消息
|
||||||
is AppEvent.MqttMessageReceived -> {
|
is AppEvent.MqttMessageReceived -> {
|
||||||
|
|||||||
@@ -1,13 +1,26 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<!-- 首页容器:ViewPager2 左右滑动(设置页 / 主页) -->
|
<!-- 首页容器:固定状态栏 + ViewPager2 左右滑动 -->
|
||||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:background="@color/background">
|
android:background="@color/background"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:paddingStart="21dp"
|
||||||
|
android:paddingTop="27dp"
|
||||||
|
android:paddingEnd="21dp">
|
||||||
|
|
||||||
|
<!-- 固定状态栏(不随 ViewPager2 滑动) -->
|
||||||
|
<com.xiaoqu.watch.ui.widget.StatusBarView
|
||||||
|
android:id="@+id/statusBar"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="24dp"
|
||||||
|
android:layout_marginBottom="3dp" />
|
||||||
|
|
||||||
|
<!-- ViewPager2 在状态栏下方滑动 -->
|
||||||
<androidx.viewpager2.widget.ViewPager2
|
<androidx.viewpager2.widget.ViewPager2
|
||||||
android:id="@+id/viewPager"
|
android:id="@+id/viewPager"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent" />
|
android:layout_height="0dp"
|
||||||
|
android:layout_weight="1" />
|
||||||
|
|
||||||
</FrameLayout>
|
</LinearLayout>
|
||||||
|
|||||||
@@ -6,17 +6,8 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:background="@color/background"
|
android:background="@color/background"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:paddingStart="21dp"
|
|
||||||
android:paddingTop="27dp"
|
|
||||||
android:paddingEnd="21dp"
|
|
||||||
android:paddingBottom="27dp">
|
android:paddingBottom="27dp">
|
||||||
|
|
||||||
<!-- 状态栏 18px → 24dp -->
|
|
||||||
<com.xiaoqu.watch.ui.widget.StatusBarView
|
|
||||||
android:id="@+id/statusBar"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="24dp" />
|
|
||||||
|
|
||||||
<!-- 可滚动内容区 -->
|
<!-- 可滚动内容区 -->
|
||||||
<ScrollView
|
<ScrollView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|||||||
@@ -7,18 +7,8 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:background="@color/background"
|
android:background="@color/background"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:paddingStart="21dp"
|
|
||||||
android:paddingTop="27dp"
|
|
||||||
android:paddingEnd="21dp"
|
|
||||||
android:paddingBottom="27dp">
|
android:paddingBottom="27dp">
|
||||||
|
|
||||||
<!-- 状态栏 18px → 24dp -->
|
|
||||||
<com.xiaoqu.watch.ui.widget.StatusBarView
|
|
||||||
android:id="@+id/statusBar"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="24dp"
|
|
||||||
android:layout_marginBottom="3dp" />
|
|
||||||
|
|
||||||
<!-- 时钟区域(flex:1 撑满中间) -->
|
<!-- 时钟区域(flex:1 撑满中间) -->
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|||||||
Reference in New Issue
Block a user