From 9c79b7ac3e4d97ef3bf3301ee1df760220db8ef4 Mon Sep 17 00:00:00 2001
From: Administrator <123>
Date: Sat, 23 Oct 2021 08:55:21 +0000
Subject: [PATCH] 首页UI布局

---
 app/src/main/java/com/duqing/missions/ui/home/HomeFragment.java |   31 +++-
 app/src/main/res/layout/home_item_classify.xml                  |   30 ++++
 app/src/main/res/drawable/bg_border_gray_corner.xml             |   12 +
 app/src/main/res/drawable/bg_border_slender_red_corner.xml      |   12 +
 app/src/main/res/layout/home_item_top.xml                       |   85 ++++++++++++
 app/src/main/res/layout/homt_item_recommend.xml                 |  128 ++++++++++++++++++
 app/src/main/res/drawable/bg_border_red_corner.xml              |   12 +
 app/src/main/res/layout/fragment_home.xml                       |   83 +++++++++--
 app/src/main/res/values/colors.xml                              |    2 
 app/build.gradle                                                |    3 
 app/src/main/res/drawable/bg_red_corner.xml                     |    9 +
 app/src/main/res/values/dimens.xml                              |    3 
 12 files changed, 384 insertions(+), 26 deletions(-)

diff --git a/app/build.gradle b/app/build.gradle
index 26eb9ec..d9ad186 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -42,4 +42,7 @@
     testImplementation 'junit:junit:4.+'
     androidTestImplementation 'androidx.test.ext:junit:1.1.2'
     androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
+    //// 注意:分包之后不会有默认的Header和Footer需要手动添加!还是原来的三种方法!
+    implementation  'com.scwang.smart:refresh-layout-kernel:2.0.1'      //核心必须依赖
+    implementation  'com.scwang.smart:refresh-header-classics:2.0.1'    //经典刷新头
 }
\ No newline at end of file
diff --git a/app/src/main/java/com/duqing/missions/ui/home/HomeFragment.java b/app/src/main/java/com/duqing/missions/ui/home/HomeFragment.java
index 6bd88b5..b93cb75 100644
--- a/app/src/main/java/com/duqing/missions/ui/home/HomeFragment.java
+++ b/app/src/main/java/com/duqing/missions/ui/home/HomeFragment.java
@@ -4,29 +4,42 @@
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
+import android.widget.ImageView;
 import android.widget.TextView;
+
 import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
 import androidx.fragment.app.Fragment;
 import androidx.lifecycle.Observer;
 import androidx.lifecycle.ViewModelProvider;
+import androidx.recyclerview.widget.GridLayoutManager;
+import androidx.recyclerview.widget.LinearLayoutManager;
+import androidx.recyclerview.widget.RecyclerView;
+
 import com.duqing.missions.R;
 import com.duqing.missions.databinding.FragmentHomeBinding;
 
 public class HomeFragment extends Fragment {
 
     private HomeViewModel homeViewModel;
-private FragmentHomeBinding binding;
+    private FragmentHomeBinding binding;
 
-    public View onCreateView(@NonNull LayoutInflater inflater,
-            ViewGroup container, Bundle savedInstanceState) {
-        homeViewModel =
-                new ViewModelProvider(this).get(HomeViewModel.class);
+    public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+        homeViewModel = new ViewModelProvider(this).get(HomeViewModel.class);
 
-    binding = FragmentHomeBinding.inflate(inflater, container, false);
-    View root = binding.getRoot();
+        binding = FragmentHomeBinding.inflate(inflater, container, false);
+        View root = binding.getRoot();
+        final  TextView textView = binding.textRecommend;
+        final ImageView imgSearch = binding.imgSearch;
+        RecyclerView recyclerClassify = binding.recyclerClassify;
+        RecyclerView recyclerTop = binding.recyclerTop;
+        final RecyclerView recyclerRecommend = binding.recyclerRecommend;
+        recyclerRecommend.setLayoutManager(new LinearLayoutManager(getContext()));
+        LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
+        layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
+        recyclerClassify.setLayoutManager(layoutManager);
+        recyclerTop.setLayoutManager(new GridLayoutManager(getContext(),3));
 
-        final TextView textView = binding.textHome;
         homeViewModel.getText().observe(getViewLifecycleOwner(), new Observer<String>() {
             @Override
             public void onChanged(@Nullable String s) {
@@ -36,7 +49,7 @@
         return root;
     }
 
-@Override
+    @Override
     public void onDestroyView() {
         super.onDestroyView();
         binding = null;
diff --git a/app/src/main/res/drawable/bg_border_gray_corner.xml b/app/src/main/res/drawable/bg_border_gray_corner.xml
new file mode 100644
index 0000000..61aee37
--- /dev/null
+++ b/app/src/main/res/drawable/bg_border_gray_corner.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+    <item>
+        <shape android:shape="rectangle">
+            <stroke
+                android:width="2dp"
+                android:color="@color/gray" />
+
+            <corners android:radius="@dimen/radios"/>
+        </shape>
+    </item>
+</selector>
\ No newline at end of file
diff --git a/app/src/main/res/drawable/bg_border_red_corner.xml b/app/src/main/res/drawable/bg_border_red_corner.xml
new file mode 100644
index 0000000..ee52996
--- /dev/null
+++ b/app/src/main/res/drawable/bg_border_red_corner.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+    <item>
+        <shape android:shape="rectangle">
+            <stroke
+                android:width="2dp"
+                android:color="@color/red" />
+
+            <corners android:radius="@dimen/small_radios"/>
+        </shape>
+    </item>
+</selector>
\ No newline at end of file
diff --git a/app/src/main/res/drawable/bg_border_slender_red_corner.xml b/app/src/main/res/drawable/bg_border_slender_red_corner.xml
new file mode 100644
index 0000000..e94d0e5
--- /dev/null
+++ b/app/src/main/res/drawable/bg_border_slender_red_corner.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+    <item>
+        <shape android:shape="rectangle">
+            <stroke
+                android:width="0.5dp"
+                android:color="@color/red" />
+
+            <corners android:radius="@dimen/small_radios"/>
+        </shape>
+    </item>
+</selector>
\ No newline at end of file
diff --git a/app/src/main/res/drawable/bg_red_corner.xml b/app/src/main/res/drawable/bg_red_corner.xml
new file mode 100644
index 0000000..c97214f
--- /dev/null
+++ b/app/src/main/res/drawable/bg_red_corner.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+    <item>
+        <shape android:shape="rectangle">
+            <solid android:color="@color/red" />
+            <corners android:radius="@dimen/small_radios"/>
+        </shape>
+    </item>
+</selector>
\ No newline at end of file
diff --git a/app/src/main/res/layout/fragment_home.xml b/app/src/main/res/layout/fragment_home.xml
index 7ecfe18..e61f67d 100644
--- a/app/src/main/res/layout/fragment_home.xml
+++ b/app/src/main/res/layout/fragment_home.xml
@@ -1,23 +1,72 @@
 <?xml version="1.0" encoding="utf-8"?>
-<androidx.constraintlayout.widget.ConstraintLayout
+<LinearLayout
     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"
+    tools:ignore="MissingConstraints"
+    tools:context=".ui.home.HomeFragment"
     android:layout_width="match_parent"
-    android:layout_height="match_parent"
-    tools:context=".ui.home.HomeFragment" >
-
-    <TextView
-        android:id="@+id/text_home"
+    android:orientation="vertical"
+    android:layout_height="match_parent">
+    <ImageView
+        android:id="@+id/img_search"
+        android:layout_width="39dp"
+        android:layout_height="35dp"
+        android:src="@android:drawable/ic_search_category_default"/>
+    <androidx.core.widget.NestedScrollView
+        android:id="@+id/smart_refresh"
         android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:layout_marginStart="8dp"
-        android:layout_marginTop="8dp"
-        android:layout_marginEnd="8dp"
-        android:textAlignment="center"
-        android:textSize="20sp"
-        app:layout_constraintEnd_toEndOf="parent"
-        app:layout_constraintStart_toStartOf="parent"
-        app:layout_constraintTop_toTopOf="parent"
-        app:layout_constraintBottom_toBottomOf="parent" />
-</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
+        android:layout_height="match_parent"
+        >
+
+        <androidx.constraintlayout.widget.ConstraintLayout
+            android:layout_width="match_parent"
+            android:layout_height="match_parent" >
+
+
+            <androidx.recyclerview.widget.RecyclerView
+                android:id="@+id/recycler_top"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
+                app:spanCount="3"
+                tools:itemCount="3"
+                tools:listitem="@layout/home_item_top" />
+
+            <androidx.recyclerview.widget.RecyclerView
+                android:id="@+id/recycler_classify"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:layout_marginTop="10dp"
+                tools:listitem="@layout/home_item_classify"
+                app:layout_constraintTop_toBottomOf="@id/recycler_top"
+                app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
+                app:spanCount="5"
+                tools:itemCount="3"
+                tools:layout_editor_absoluteX="1dp"
+                tools:layout_editor_absoluteY="247dp"/>
+
+            <TextView
+                android:id="@+id/text_recommend"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                app:layout_constraintTop_toBottomOf="@id/recycler_classify"
+                app:layout_constraintLeft_toLeftOf="parent"
+                android:textSize="14dp"
+                android:text="任务推荐"
+                android:textColor="@color/black"
+                android:layout_margin="@dimen/frame_margin_lr" />
+
+            <androidx.recyclerview.widget.RecyclerView
+                android:id="@+id/recycler_recommend"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                tools:listitem="@layout/homt_item_recommend"
+                app:layout_constraintLeft_toLeftOf="parent"
+                app:layout_constraintTop_toBottomOf="@id/text_recommend"
+                />
+
+        </androidx.constraintlayout.widget.ConstraintLayout>
+    </androidx.core.widget.NestedScrollView>
+
+</LinearLayout>
\ No newline at end of file
diff --git a/app/src/main/res/layout/home_item_classify.xml b/app/src/main/res/layout/home_item_classify.xml
new file mode 100644
index 0000000..493a4b8
--- /dev/null
+++ b/app/src/main/res/layout/home_item_classify.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<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:layout_marginRight="10dp"
+    android:layout_marginLeft="10dp"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content">
+
+    <ImageView
+        android:id="@+id/img_icon"
+        android:layout_width="80dp"
+        android:layout_height="wrap_content"
+        android:adjustViewBounds="true"
+        tools:srcCompat="@tools:sample/avatars"
+        app:layout_constraintTop_toTopOf="parent"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintLeft_toLeftOf="parent"
+        app:layout_constraintRight_toRightOf="parent"/>
+
+    <TextView
+        android:id="@+id/textView"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:text="TextView"
+        android:layout_marginTop="8dp"
+        app:layout_constraintTop_toBottomOf="@id/img_icon"
+        app:layout_constraintLeft_toLeftOf="parent"
+        app:layout_constraintRight_toRightOf="parent" />
+</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
diff --git a/app/src/main/res/layout/home_item_top.xml b/app/src/main/res/layout/home_item_top.xml
new file mode 100644
index 0000000..7362407
--- /dev/null
+++ b/app/src/main/res/layout/home_item_top.xml
@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="utf-8"?>
+<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:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:background="@drawable/bg_border_gray_corner"
+    android:layout_marginLeft="5dp"
+    android:layout_marginTop="5dp"
+    android:layout_marginRight="5dp"
+    android:padding="10dp"
+    tools:ignore="MissingConstraints">
+
+    <TextView
+        android:id="@+id/txt_type"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:text="TextView"
+        android:textSize="13sp"
+        android:textColor="@color/red"
+        android:paddingLeft="8dp"
+        android:paddingRight="8dp"
+        android:paddingTop="3dp"
+        android:paddingBottom="3dp"
+        android:background="@drawable/bg_border_red_corner"
+        tools:layout_editor_absoluteX="0dp"
+        tools:layout_editor_absoluteY="4dp"
+        tools:text="类型" />
+
+    <TextView
+        android:id="@+id/txt_title"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginStart="4dp"
+        android:text="任务标题\nl;ajsdlfkjalsjd"
+        android:textColor="@color/black"
+        android:layout_marginTop="10dp"
+        app:layout_constraintTop_toBottomOf="@id/txt_type"
+        tools:layout_editor_absoluteY="23dp" />
+
+    <TextView
+        android:id="@+id/txt_label"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:background="@drawable/bg_red_corner"
+        android:text="标签"
+        android:textSize="10sp"
+        android:textColor="@color/white"
+        android:padding="3dp"
+        android:layout_marginRight="10dp"
+        app:layout_constraintBottom_toBottomOf="@id/txt_title"
+        app:layout_constraintTop_toTopOf="@id/image_head"/>
+
+    <TextView
+        android:id="@+id/txt_detail"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:text="参与人数\n剩余数量"
+        android:layout_marginTop="8dp"
+        android:layout_marginLeft="10dp"
+        app:layout_constraintLeft_toRightOf="@id/txt_label"
+        app:layout_constraintTop_toBottomOf="@id/txt_title" />
+
+    <ImageView
+        android:id="@+id/image_head"
+        android:layout_width="43dp"
+        android:layout_height="32dp"
+        android:scaleType="centerCrop"
+        android:layout_marginTop="8dp"
+        app:layout_constraintTop_toBottomOf="@id/txt_detail"
+        tools:srcCompat="@tools:sample/avatars" />
+
+    <TextView
+        android:id="@+id/txt_price"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:text="TextView"
+        android:layout_marginLeft="10dp"
+        android:textColor="@color/red"
+        app:layout_constraintLeft_toRightOf="@id/image_head"
+        app:layout_constraintTop_toTopOf="@id/image_head"
+        app:layout_constraintBottom_toBottomOf="@id/image_head"
+        tools:text="+ 35.00元" />
+
+</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
diff --git a/app/src/main/res/layout/homt_item_recommend.xml b/app/src/main/res/layout/homt_item_recommend.xml
new file mode 100644
index 0000000..0974968
--- /dev/null
+++ b/app/src/main/res/layout/homt_item_recommend.xml
@@ -0,0 +1,128 @@
+<?xml version="1.0" encoding="utf-8"?>
+<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:padding="@dimen/frame_margin_lr"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content">
+
+    <ImageView
+        android:id="@+id/image_head"
+        android:layout_width="50dp"
+        android:layout_height="50dp"
+        app:layout_constraintLeft_toLeftOf="parent"
+        app:layout_constraintTop_toTopOf="parent"
+        app:layout_constraintBottom_toBottomOf="parent"
+        tools:srcCompat="@tools:sample/avatars" />
+
+    <TextView
+        android:id="@+id/txt_title"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:textColor="@color/black"
+        android:text="标题"
+        android:textSize="14sp"
+        android:layout_marginLeft="@dimen/frame_margin_lr"
+        app:layout_constraintLeft_toRightOf="@id/image_head"
+        app:layout_constraintTop_toTopOf="parent"
+        />
+
+    <TextView
+        android:id="@+id/txt_label"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:text="标签"
+        android:textColor="@color/red"
+        android:layout_marginTop="4dp"
+        android:paddingLeft="4dp"
+        android:paddingRight="4dp"
+        android:paddingTop="2dp"
+        android:paddingBottom="2dp"
+        android:textSize="10sp"
+        android:background="@drawable/bg_border_slender_red_corner"
+        android:layout_marginLeft="@dimen/frame_margin_lr"
+        app:layout_constraintTop_toBottomOf="@id/txt_title"
+        app:layout_constraintLeft_toRightOf="@id/image_head"/>
+
+    <TextView
+        android:id="@+id/txt_detail"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginTop="3dp"
+        android:text="100人完成 | 剩余数100"
+        android:layout_marginLeft="@dimen/frame_margin_lr"
+        app:layout_constraintTop_toBottomOf="@id/txt_label"
+        app:layout_constraintLeft_toRightOf="@id/image_head" />
+
+    <androidx.constraintlayout.widget.ConstraintLayout
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        app:layout_constraintRight_toRightOf="parent"
+        app:layout_constraintTop_toTopOf="parent"
+        app:layout_constraintBottom_toBottomOf="parent">
+
+        <TextView
+            android:id="@+id/txt_index"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="顶"
+            android:paddingLeft="3dp"
+            android:paddingRight="3dp"
+            android:textSize="10sp"
+            android:background="@drawable/bg_red_corner"
+            android:textColor="@color/white"
+            android:layout_marginRight="10dp"
+            app:layout_goneMarginRight="0dp"
+            app:layout_constraintBottom_toTopOf="@id/txt_price"
+            app:layout_constraintHorizontal_chainStyle="spread"
+            app:layout_constraintHorizontal_weight="1"
+            app:layout_constraintLeft_toLeftOf="parent"
+            app:layout_constraintRight_toLeftOf="@id/txt_recommend"/>
+
+        <TextView
+            android:id="@+id/txt_recommend"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="推"
+            android:paddingLeft="3dp"
+            android:paddingRight="3dp"
+            android:textSize="10sp"
+            android:background="@drawable/bg_red_corner"
+            android:textColor="@color/white"
+            android:layout_marginRight="10dp"
+            android:visibility="gone"
+            app:layout_goneMarginRight="0dp"
+            app:layout_constraintBottom_toTopOf="@id/txt_price"
+            app:layout_constraintHorizontal_chainStyle="spread"
+            app:layout_constraintHorizontal_weight="1"
+            app:layout_constraintRight_toLeftOf="@id/txt_deposit"
+            app:layout_constraintLeft_toRightOf="@id/txt_index"/>
+
+        <TextView
+            android:id="@+id/txt_deposit"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="保"
+            android:paddingLeft="3dp"
+            android:paddingRight="3dp"
+            android:textSize="10sp"
+            android:background="@drawable/bg_red_corner"
+            android:textColor="@color/white"
+            android:visibility="gone"
+            app:layout_constraintBottom_toTopOf="@id/txt_price"
+            app:layout_constraintHorizontal_chainStyle="spread"
+            app:layout_constraintHorizontal_weight="1"
+            app:layout_constraintLeft_toRightOf="@id/txt_recommend"
+            app:layout_constraintRight_toRightOf="parent"/>
+
+        <TextView
+            android:id="@+id/txt_price"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="+ 35.00元"
+            android:textColor="@color/red"
+            app:layout_constraintLeft_toLeftOf="parent"
+            app:layout_constraintRight_toRightOf="parent"
+            app:layout_constraintBottom_toBottomOf="parent" />
+    </androidx.constraintlayout.widget.ConstraintLayout>
+</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml
index f8c6127..9b5825e 100644
--- a/app/src/main/res/values/colors.xml
+++ b/app/src/main/res/values/colors.xml
@@ -7,4 +7,6 @@
     <color name="teal_700">#FF018786</color>
     <color name="black">#FF000000</color>
     <color name="white">#FFFFFFFF</color>
+    <color name="red">#FF1414</color>
+    <color name="gray">#CDCDCD</color>
 </resources>
\ No newline at end of file
diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml
index e00c2dd..34a4985 100644
--- a/app/src/main/res/values/dimens.xml
+++ b/app/src/main/res/values/dimens.xml
@@ -2,4 +2,7 @@
     <!-- Default screen margins, per the Android Design guidelines. -->
     <dimen name="activity_horizontal_margin">16dp</dimen>
     <dimen name="activity_vertical_margin">16dp</dimen>
+    <dimen name="small_radios">3dp</dimen>
+    <dimen name="radios">10dp</dimen>
+    <dimen name="frame_margin_lr">10dp</dimen>
 </resources>
\ No newline at end of file

--
Gitblit v1.9.1