Explorar el Código

调整加载顺序

Signed-off-by: duanchangpeng <838560574@qq.com>
duanchangpeng hace 5 años
padre
commit
aeb3712ef2

+ 12 - 14
app/src/main/java/com/example/watch/ui/activity/MainActivity.kt

@@ -60,12 +60,12 @@ class MainActivity : AppCompatActivity(), ScannerFragment.OnDeviceSelectedListen
 
     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
-
-        initView();
-
+        setContentView(R.layout.activity_main)
 //        首次加载
         FirstRun()
 
+        initView();
+
 //        连接心率带
         linkHeartBand()
 
@@ -148,11 +148,10 @@ class MainActivity : AppCompatActivity(), ScannerFragment.OnDeviceSelectedListen
         val sharedPreferences = getSharedPreferences("FirstRun", 0)
         val first_run = sharedPreferences.getBoolean("First", true)
         if (first_run) {
-            sharedPreferences.edit().putBoolean("First", false).commit()
+            sharedPreferences.edit().putBoolean("First", false).apply()
             val OneActivityIntent = Intent(this, OneActivity::class.java)
             startActivity(OneActivityIntent)
         } else {
-
 //            setContentView(R.layout.activity_main)
             //        登录判断
             login()
@@ -162,9 +161,8 @@ class MainActivity : AppCompatActivity(), ScannerFragment.OnDeviceSelectedListen
     private fun login() {
         val sharedPreferences = getSharedPreferences("login", 0)
         val loginState = sharedPreferences.getBoolean("token", true)
-//        val loginState = true
         if (loginState) {
-            sharedPreferences.edit().putBoolean("token", false).commit()
+            sharedPreferences.edit().putBoolean("token", false).apply()
             startActivity(Intent(this, LoginActivity::class.java))
         } else {
             setContentView(R.layout.activity_main)
@@ -508,13 +506,13 @@ class MainActivity : AppCompatActivity(), ScannerFragment.OnDeviceSelectedListen
                         .name("心率趋势图")
                         .data(
                             arrayOf(
-                                70,
-                                79,
-                                112,
-                                92,
-                                87,
-                                77,
-                                98
+                                0,
+                                0,
+                                0,
+                                0,
+                                0,
+                                0,
+                                0
                             )
                         )
                 )

+ 5 - 181
app/src/main/res/layout/activity_main.xml

@@ -12,188 +12,12 @@
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:background="#FCFCFC"
-        android:orientation="vertical"
-        tools:layout_editor_absoluteX="-85dp"
-        tools:layout_editor_absoluteY="82dp">
-
-        <LinearLayout
-            android:id="@+id/main_top"
+        android:orientation="vertical">
+        <include
             android:layout_width="match_parent"
-            android:layout_height="195dp"
-            android:orientation="horizontal">
-
-            <LinearLayout
-                android:id="@+id/head_bg"
-                android:layout_width="match_parent"
-                android:layout_height="match_parent"
-                android:layout_weight="1"
-                android:background="#028FE1"
-                android:orientation="vertical">
-
-                <TextView
-                    android:id="@+id/head_status"
-                    android:layout_width="match_parent"
-                    android:layout_height="58dp"
-                    android:layout_weight="1"
-                    android:gravity="center"
-                    android:text="心率带未连接  电量 0%"
-                    android:textColor="@color/white" />
-
-                <LinearLayout
-                    android:layout_width="match_parent"
-                    android:layout_height="match_parent"
-                    android:layout_weight="1"
-                    android:orientation="horizontal">
-
-                    <LinearLayout
-                        android:layout_width="match_parent"
-                        android:layout_height="match_parent"
-                        android:layout_weight="1"
-                        android:orientation="vertical">
-
-                        <RelativeLayout
-                            android:layout_width="match_parent"
-                            android:layout_height="105dp">
-
-                            <TextView
-                                android:id="@+id/activLevel"
-                                android:layout_width="match_parent"
-                                android:layout_height="82dp"
-                                android:layout_weight="1"
-                                android:gravity="center"
-                                android:text="0"
-                                android:textColor="@color/white"
-                                android:textSize="50dp" />
-
-                            <TextView
-                                android:id="@+id/percentIcon"
-                                android:layout_width="40dp"
-                                android:layout_height="82dp"
-                                android:layout_alignParentTop="true"
-                                android:layout_alignParentRight="true"
-                                android:layout_marginTop="10dp"
-                                android:paddingLeft="10dp"
-                                android:text="%"
-                                android:textColor="@color/white"
-                                android:textSize="20dp" />
-                        </RelativeLayout>
-
-                        <TextView
-                            android:id="@+id/act_level_text"
-                            android:layout_width="90dp"
-                            android:layout_height="30dp"
-                            android:layout_gravity="center"
-                            android:background="@drawable/circle_btn"
-                            android:gravity="center"
-                            android:text="激活放松"
-                            android:textColor="@color/white" />
-                    </LinearLayout>
-
-                    <LinearLayout
-                        android:layout_width="match_parent"
-                        android:layout_height="match_parent"
-                        android:layout_weight="1"
-                        android:orientation="vertical">
-
-                        <ImageView
-                            android:id="@+id/imageView"
-                            android:layout_width="match_parent"
-                            android:layout_height="97dp"
-                            android:layout_centerHorizontal="true"
-                            android:gravity="center"
-                            android:src="@drawable/head" />
-
-                        <LinearLayout
-                            android:layout_width="match_parent"
-                            android:layout_height="match_parent"
-                            android:layout_weight="1"
-                            android:orientation="horizontal">
-
-                            <RelativeLayout
-                                android:layout_width="match_parent"
-                                android:layout_height="match_parent">
-
-                                <TextView
-                                    android:id="@+id/textView10"
-                                    android:layout_width="match_parent"
-                                    android:layout_height="match_parent"
-                                    android:layout_gravity="center"
-                                    android:layout_weight="1"
-                                    android:gravity="center_vertical|center"
-                                    android:text="王仪涵"
-                                    android:textColor="@color/white" />
-
-                                <ImageView
-                                    android:id="@+id/sex"
-                                    android:layout_width="18dp"
-                                    android:layout_height="18dp"
-                                    android:layout_alignParentRight="true"
-                                    android:layout_gravity="center"
-                                    android:layout_marginTop="25dp"
-                                    android:layout_marginRight="20dp"
-                                    android:gravity="center_vertical|left"
-                                    android:src="@drawable/male" />
-                            </RelativeLayout>
-                        </LinearLayout>
-                    </LinearLayout>
-
-                    <LinearLayout
-                        android:layout_width="match_parent"
-                        android:layout_height="match_parent"
-                        android:layout_weight="1"
-                        android:orientation="vertical">
-
-                        <LinearLayout
-                            android:layout_width="match_parent"
-                            android:layout_height="match_parent"
-                            android:layout_weight="1"
-                            android:orientation="vertical">
-
-                            <RelativeLayout
-                                android:layout_width="match_parent"
-                                android:layout_height="105dp">
-
-                                <TextView
-                                    android:id="@+id/heartReal"
-                                    android:layout_width="match_parent"
-                                    android:layout_height="82dp"
-                                    android:layout_weight="1"
-                                    android:gravity="center"
-                                    android:text="0"
-                                    android:textColor="@color/white"
-                                    android:textSize="50dp" />
-
-                                <ImageView
-                                    android:id="@+id/heart"
-                                    android:layout_width="20dp"
-                                    android:layout_height="20dp"
-                                    android:layout_alignParentTop="true"
-                                    android:layout_alignParentRight="true"
-                                    android:layout_centerHorizontal="true"
-                                    android:layout_marginTop="17dp"
-                                    android:layout_marginRight="5dp"
-                                    android:gravity="center"
-                                    android:src="@drawable/heart" />
-                            </RelativeLayout>
-
-                            <TextView
-                                android:id="@+id/curentHr"
-                                android:layout_width="90dp"
-                                android:layout_height="30dp"
-                                android:layout_gravity="center"
-                                android:background="@drawable/circle_btn"
-                                android:gravity="center"
-                                android:text="瞬时心率"
-                                android:textColor="@color/white" />
-                        </LinearLayout>
-                    </LinearLayout>
-
-                </LinearLayout>
-
-            </LinearLayout>
-
-        </LinearLayout>
-
+            android:layout_height="wrap_content"
+            android:layout_centerHorizontal="true"
+            layout="@layout/main_top" />
         <include
             android:layout_width="match_parent"
             android:layout_height="match_parent"

+ 185 - 0
app/src/main/res/layout/main_top.xml

@@ -0,0 +1,185 @@
+<?xml version="1.0" encoding="utf-8"?>
+<androidx.constraintlayout.widget.ConstraintLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent">
+    <LinearLayout
+        android:id="@+id/main_top"
+        android:layout_width="match_parent"
+        android:layout_height="185dp"
+        android:orientation="vertical"
+        tools:ignore="MissingConstraints">
+
+        <LinearLayout
+            android:id="@+id/head_bg"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent"
+            android:layout_weight="1"
+            android:background="#028FE1"
+            android:orientation="vertical">
+
+            <TextView
+                android:id="@+id/head_status"
+                android:layout_width="match_parent"
+                android:layout_height="58dp"
+                android:layout_weight="1"
+                android:gravity="center"
+                android:text="心率带未连接  电量 0%"
+                android:textColor="@color/white" />
+
+            <LinearLayout
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"
+                android:layout_weight="1"
+                android:orientation="horizontal">
+
+                <LinearLayout
+                    android:layout_width="match_parent"
+                    android:layout_height="match_parent"
+                    android:layout_weight="1"
+                    android:orientation="vertical">
+
+                    <RelativeLayout
+                        android:layout_width="match_parent"
+                        android:layout_height="105dp">
+
+                        <TextView
+                            android:id="@+id/activLevel"
+                            android:layout_width="match_parent"
+                            android:layout_height="82dp"
+                            android:layout_weight="1"
+                            android:gravity="center"
+                            android:text="0"
+                            android:textColor="@color/white"
+                            android:textSize="50dp" />
+
+                        <TextView
+                            android:id="@+id/percentIcon"
+                            android:layout_width="40dp"
+                            android:layout_height="82dp"
+                            android:layout_alignParentTop="true"
+                            android:layout_alignParentRight="true"
+                            android:layout_marginTop="10dp"
+                            android:paddingLeft="10dp"
+                            android:text="%"
+                            android:textColor="@color/white"
+                            android:textSize="20dp" />
+                    </RelativeLayout>
+
+                    <TextView
+                        android:id="@+id/act_level_text"
+                        android:layout_width="90dp"
+                        android:layout_height="30dp"
+                        android:layout_gravity="center"
+                        android:background="@drawable/circle_btn"
+                        android:gravity="center"
+                        android:text="激活放松"
+                        android:textColor="@color/white" />
+                </LinearLayout>
+
+                <LinearLayout
+                    android:layout_width="match_parent"
+                    android:layout_height="match_parent"
+                    android:layout_weight="1"
+                    android:orientation="vertical">
+
+                    <ImageView
+                        android:id="@+id/imageView"
+                        android:layout_width="match_parent"
+                        android:layout_height="97dp"
+                        android:layout_centerHorizontal="true"
+                        android:gravity="center"
+                        android:src="@drawable/head" />
+
+                    <LinearLayout
+                        android:layout_width="match_parent"
+                        android:layout_height="match_parent"
+                        android:layout_weight="1"
+                        android:orientation="horizontal">
+
+                        <RelativeLayout
+                            android:layout_width="match_parent"
+                            android:layout_height="match_parent">
+
+                            <TextView
+                                android:id="@+id/textView10"
+                                android:layout_width="match_parent"
+                                android:layout_height="match_parent"
+                                android:layout_gravity="center"
+                                android:layout_weight="1"
+                                android:gravity="center_vertical|center"
+                                android:text="王仪涵"
+                                android:textColor="@color/white" />
+
+                            <ImageView
+                                android:id="@+id/sex"
+                                android:layout_width="18dp"
+                                android:layout_height="18dp"
+                                android:layout_alignParentRight="true"
+                                android:layout_gravity="center"
+                                android:layout_marginTop="20dp"
+                                android:layout_marginRight="20dp"
+                                android:gravity="center_vertical|left"
+                                android:src="@drawable/male" />
+                        </RelativeLayout>
+                    </LinearLayout>
+                </LinearLayout>
+
+                <LinearLayout
+                    android:layout_width="match_parent"
+                    android:layout_height="match_parent"
+                    android:layout_weight="1"
+                    android:orientation="vertical">
+
+                    <LinearLayout
+                        android:layout_width="match_parent"
+                        android:layout_height="match_parent"
+                        android:layout_weight="1"
+                        android:orientation="vertical">
+
+                        <RelativeLayout
+                            android:layout_width="match_parent"
+                            android:layout_height="105dp">
+
+                            <TextView
+                                android:id="@+id/heartReal"
+                                android:layout_width="match_parent"
+                                android:layout_height="82dp"
+                                android:layout_weight="1"
+                                android:gravity="center"
+                                android:text="0"
+                                android:textColor="@color/white"
+                                android:textSize="50dp" />
+
+                            <ImageView
+                                android:id="@+id/heart"
+                                android:layout_width="20dp"
+                                android:layout_height="20dp"
+                                android:layout_alignParentTop="true"
+                                android:layout_alignParentRight="true"
+                                android:layout_centerHorizontal="true"
+                                android:layout_marginTop="17dp"
+                                android:layout_marginRight="5dp"
+                                android:gravity="center"
+                                android:src="@drawable/heart" />
+                        </RelativeLayout>
+
+                        <TextView
+                            android:id="@+id/curentHr"
+                            android:layout_width="90dp"
+                            android:layout_height="30dp"
+                            android:layout_gravity="center"
+                            android:background="@drawable/circle_btn"
+                            android:gravity="center"
+                            android:text="瞬时心率"
+                            android:textColor="@color/white" />
+                    </LinearLayout>
+                </LinearLayout>
+
+            </LinearLayout>
+
+        </LinearLayout>
+
+    </LinearLayout>
+</androidx.constraintlayout.widget.ConstraintLayout>