├── app
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ ├── mipmap-xhdpi
│ │ │ ├── ic_back.png
│ │ │ ├── ic_test1.jpg
│ │ │ ├── ic_test2.jpg
│ │ │ ├── ic_test3.jpg
│ │ │ ├── ic_search.png
│ │ │ ├── ic_launcher.png
│ │ │ ├── ic_arrow_right.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-hdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── values
│ │ │ ├── strings.xml
│ │ │ ├── colors.xml
│ │ │ └── styles.xml
│ │ ├── mipmap-anydpi-v26
│ │ │ ├── ic_launcher.xml
│ │ │ └── ic_launcher_round.xml
│ │ ├── menu
│ │ │ └── menu_home_serach.xml
│ │ ├── layout
│ │ │ ├── fragment_test.xml
│ │ │ ├── item_test.xml
│ │ │ ├── activity_main.xml
│ │ │ ├── item_header.xml
│ │ │ └── item_recommend.xml
│ │ ├── drawable-v24
│ │ │ └── ic_launcher_foreground.xml
│ │ └── drawable
│ │ │ └── ic_launcher_background.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── com
│ │ └── leiyun
│ │ └── elemalist
│ │ ├── App.kt
│ │ ├── SquareImageView.java
│ │ ├── TestFragment.kt
│ │ ├── MainActivity.kt
│ │ └── TestAdapter.kt
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── screenshot
├── 1.gif
├── 2.gif
└── 3.gif
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── gradle.properties
├── gradlew.bat
├── gradlew
└── README.md
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/screenshot/1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leiyun-studio/ELeMaList/HEAD/screenshot/1.gif
--------------------------------------------------------------------------------
/screenshot/2.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leiyun-studio/ELeMaList/HEAD/screenshot/2.gif
--------------------------------------------------------------------------------
/screenshot/3.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leiyun-studio/ELeMaList/HEAD/screenshot/3.gif
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leiyun-studio/ELeMaList/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_back.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leiyun-studio/ELeMaList/HEAD/app/src/main/res/mipmap-xhdpi/ic_back.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_test1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leiyun-studio/ELeMaList/HEAD/app/src/main/res/mipmap-xhdpi/ic_test1.jpg
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_test2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leiyun-studio/ELeMaList/HEAD/app/src/main/res/mipmap-xhdpi/ic_test2.jpg
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_test3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leiyun-studio/ELeMaList/HEAD/app/src/main/res/mipmap-xhdpi/ic_test3.jpg
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leiyun-studio/ELeMaList/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leiyun-studio/ELeMaList/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_search.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leiyun-studio/ELeMaList/HEAD/app/src/main/res/mipmap-xhdpi/ic_search.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leiyun-studio/ELeMaList/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leiyun-studio/ELeMaList/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leiyun-studio/ELeMaList/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_arrow_right.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leiyun-studio/ELeMaList/HEAD/app/src/main/res/mipmap-xhdpi/ic_arrow_right.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leiyun-studio/ELeMaList/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leiyun-studio/ELeMaList/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leiyun-studio/ELeMaList/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leiyun-studio/ELeMaList/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leiyun-studio/ELeMaList/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | ELeMaList
3 |
4 |
5 | Hello blank fragment
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #01A7FF
4 | #01A7FF
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Nov 09 15:41:54 CST 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_home_serach.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_test.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | android.enableJetifier=true
13 | android.useAndroidX=true
14 | org.gradle.jvmargs=-Xmx1536m
15 |
16 | # When configured, Gradle will run in incubating parallel mode.
17 | # This option should only be used with decoupled projects. More details, visit
18 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
19 | # org.gradle.parallel=true
20 |
--------------------------------------------------------------------------------
/app/src/main/java/com/leiyun/elemalist/App.kt:
--------------------------------------------------------------------------------
1 | package com.leiyun.elemalist
2 |
3 | import android.app.Application
4 | import android.graphics.Color
5 | import com.scwang.smartrefresh.header.MaterialHeader
6 | import com.scwang.smartrefresh.layout.SmartRefreshLayout
7 | import com.scwang.smartrefresh.layout.constant.SpinnerStyle
8 | import com.scwang.smartrefresh.layout.footer.ClassicsFooter
9 |
10 | /**
11 | * 类名:App
12 | * 作者:Yun.Lei
13 | * 功能:
14 | * 创建日期:2017-11-09 18:13
15 | * 修改人:
16 | * 修改时间:
17 | * 修改备注:
18 | */
19 | class App : Application() {
20 |
21 | init {
22 | SmartRefreshLayout.setDefaultRefreshHeaderCreator { context, layout ->
23 | layout.setPrimaryColors(context.resources.getColor(R.color.colorPrimary), Color.WHITE)
24 | return@setDefaultRefreshHeaderCreator MaterialHeader(context)
25 | }
26 | SmartRefreshLayout.setDefaultRefreshFooterCreator { context, _ ->
27 | ClassicsFooter(context).setSpinnerStyle(SpinnerStyle.Translate)
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/leiyun/elemalist/SquareImageView.java:
--------------------------------------------------------------------------------
1 | package com.leiyun.elemalist;
2 |
3 | import android.content.Context;
4 | import androidx.appcompat.widget.AppCompatImageView;
5 | import android.util.AttributeSet;
6 |
7 | /**
8 | * 正方形ImageView
9 | */
10 | public class SquareImageView extends AppCompatImageView {
11 |
12 | public SquareImageView(Context context) {
13 | super(context);
14 | }
15 |
16 | public SquareImageView(Context context, AttributeSet attrs) {
17 | this(context, attrs, 0);
18 | }
19 |
20 | public SquareImageView(Context context, AttributeSet attrs, int defStyle) {
21 | super(context, attrs, defStyle);
22 |
23 | }
24 |
25 | @Override
26 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
27 | setMeasuredDimension(getDefaultSize(0, widthMeasureSpec), getDefaultSize(0, heightMeasureSpec));
28 | int childWidthSize = getMeasuredWidth();
29 | //高度和宽度一样
30 | heightMeasureSpec = widthMeasureSpec = MeasureSpec.makeMeasureSpec(childWidthSize, MeasureSpec.EXACTLY);
31 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
32 | }
33 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_test.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
19 |
20 |
27 |
28 |
29 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/java/com/leiyun/elemalist/TestFragment.kt:
--------------------------------------------------------------------------------
1 | package com.leiyun.elemalist
2 |
3 |
4 | import android.os.Bundle
5 | import android.view.LayoutInflater
6 | import android.view.View
7 | import android.view.ViewGroup
8 | import androidx.fragment.app.Fragment
9 | import com.jay.widget.StickyHeadersLinearLayoutManager
10 | import kotlinx.android.synthetic.main.fragment_test.*
11 |
12 |
13 | /**
14 | * A simple [Fragment] subclass.
15 | */
16 | class TestFragment : Fragment() {
17 |
18 | var position = 0
19 |
20 | override fun onCreate(savedInstanceState: Bundle?) {
21 | super.onCreate(savedInstanceState)
22 | position = arguments?.getInt("position") ?: 0
23 | }
24 |
25 |
26 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
27 | // Inflate the layout for this fragment
28 | return inflater.inflate(R.layout.fragment_test, container, false)
29 | }
30 |
31 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
32 | super.onViewCreated(view, savedInstanceState)
33 |
34 | val layoutManager = StickyHeadersLinearLayoutManager(activity)
35 | recycler_view.layoutManager = layoutManager
36 | val adapter = TestAdapter(position == 0)
37 | recycler_view.adapter = adapter
38 |
39 |
40 | refreshLayout.setOnRefreshListener {
41 | refreshLayout.finishRefresh(1500) //模拟数据刷新
42 | }
43 |
44 | refreshLayout.setOnLoadMoreListener {
45 | refreshLayout.finishLoadMore(1500)//模拟加载更多
46 | }
47 |
48 | }
49 |
50 | }// Required empty public constructor
51 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | apply plugin: 'kotlin-android'
4 |
5 | apply plugin: 'kotlin-android-extensions'
6 |
7 | android {
8 | compileSdkVersion 28
9 | buildToolsVersion "29.0.2"
10 | defaultConfig {
11 | applicationId "com.leiyun.elemalist"
12 | minSdkVersion 19
13 | targetSdkVersion 28
14 | versionCode 1
15 | versionName "1.0.1.0"
16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
17 | }
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 | }
25 |
26 | dependencies {
27 | implementation fileTree(include: ['*.jar'], dir: 'libs')
28 | // implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
29 | implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
30 |
31 | implementation 'androidx.appcompat:appcompat:1.1.0'
32 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
33 | testImplementation 'junit:junit:4.12'
34 | androidTestImplementation 'androidx.test.ext:junit:1.1.1'
35 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
36 | implementation 'androidx.legacy:legacy-support-v4:1.0.0'
37 | implementation 'com.google.android.material:material:1.0.0'
38 | implementation 'androidx.recyclerview:recyclerview:1.1.0'
39 | implementation 'com.flyco.tablayout:FlycoTabLayout_Lib:2.1.2@aar'
40 | implementation 'com.timehop.stickyheadersrecyclerview:library:[0.4.3]@aar'
41 | implementation 'com.scwang.smartrefresh:SmartRefreshLayout:1.1.0'
42 | implementation 'com.scwang.smartrefresh:SmartRefreshHeader:1.1.0'//没有使用特殊Header,可以不加这行
43 | implementation 'com.github.qiujayen:sticky-layoutmanager:1.0.1'
44 | }
45 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
21 |
22 |
31 |
32 |
33 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_header.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
19 |
20 |
28 |
29 |
37 |
38 |
46 |
47 |
48 |
53 |
54 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/java/com/leiyun/elemalist/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.leiyun.elemalist
2 |
3 | import android.os.Bundle
4 | import androidx.fragment.app.Fragment
5 | import androidx.fragment.app.FragmentManager
6 | import androidx.fragment.app.FragmentPagerAdapter
7 | import androidx.viewpager.widget.ViewPager
8 | import androidx.appcompat.app.AppCompatActivity
9 | import androidx.appcompat.widget.Toolbar
10 | import android.view.Menu
11 | import com.flyco.tablayout.SlidingTabLayout
12 | import kotlinx.android.synthetic.main.activity_main.*
13 |
14 | class MainActivity : AppCompatActivity() {
15 |
16 | private lateinit var mToolBar: Toolbar
17 | private lateinit var mViewPager: ViewPager
18 | private lateinit var mTabLayout: SlidingTabLayout
19 | private val titles = mutableListOf("全部", "卤味", "麻辣小吃", "精品蛋糕", "水果", "咖啡","奶茶果汁","面包","牛奶")
20 |
21 | override fun onCreate(savedInstanceState: Bundle?) {
22 | super.onCreate(savedInstanceState)
23 | setContentView(R.layout.activity_main)
24 | mToolBar = findViewById(R.id.toolbar)
25 | mViewPager = findViewById(R.id.viewPager)
26 | mTabLayout = findViewById(R.id.tabLayout)
27 | mToolBar.title = "下午茶"
28 | mToolBar.setNavigationIcon(R.mipmap.ic_back)
29 | setSupportActionBar(toolbar)
30 | mViewPager.adapter = MyViewPagerAdapter(titles, supportFragmentManager)
31 | mTabLayout.setViewPager(mViewPager)
32 | }
33 |
34 | override fun onCreateOptionsMenu(menu: Menu?): Boolean {
35 | menuInflater.inflate(R.menu.menu_home_serach,menu)
36 | return true
37 | }
38 | }
39 |
40 | class MyViewPagerAdapter(private val titles: MutableList, fm: FragmentManager) : androidx.fragment.app.FragmentPagerAdapter(fm) {
41 | override fun getItem(position: Int): Fragment {
42 | val fragment = TestFragment()
43 | val arguments = Bundle()
44 | arguments.putInt("position",position)
45 | fragment.arguments = arguments
46 | return fragment
47 | }
48 |
49 | override fun getCount(): Int = titles.size
50 |
51 | override fun getPageTitle(position: Int): CharSequence = titles[position]
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/app/src/main/java/com/leiyun/elemalist/TestAdapter.kt:
--------------------------------------------------------------------------------
1 | package com.leiyun.elemalist
2 |
3 | import android.view.LayoutInflater
4 | import android.view.View
5 | import android.view.ViewGroup
6 | import android.widget.ImageView
7 | import android.widget.TextView
8 | import android.widget.Toast
9 | import androidx.recyclerview.widget.RecyclerView
10 | import com.jay.widget.StickyHeaders
11 |
12 | /**
13 | * 类名:TestAdapter
14 | * 作者:Yun.Lei
15 | * 功能:
16 | * 创建日期:2017-11-09 16:12
17 | * 修改人:
18 | * 修改时间:
19 | * 修改备注:
20 | */
21 | class TestAdapter(private var isHome: Boolean) : RecyclerView.Adapter(), StickyHeaders {
22 |
23 | override fun isStickyHeader(position: Int): Boolean {
24 | return if (isHome) {
25 | position == 1
26 | } else {
27 | position == 0
28 | }
29 | }
30 |
31 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
32 | val view = LayoutInflater.from(parent!!.context).inflate(viewType, parent, false)
33 | return when (viewType) {
34 | R.layout.item_recommend -> {
35 | view.setOnClickListener {
36 | Toast.makeText(parent.context, "点击", Toast.LENGTH_SHORT).show()
37 | }
38 | RecommendViewHolder(view)
39 | }
40 | R.layout.item_header -> {
41 | view.findViewById(R.id.type1).setOnClickListener { Toast.makeText(parent.context, "综合排序", Toast.LENGTH_SHORT).show() }
42 | view.findViewById(R.id.type2).setOnClickListener { Toast.makeText(parent.context, "好评优先", Toast.LENGTH_SHORT).show() }
43 | view.findViewById(R.id.type3).setOnClickListener { Toast.makeText(parent.context, "距离最近", Toast.LENGTH_SHORT).show() }
44 | view.findViewById(R.id.type4).setOnClickListener { Toast.makeText(parent.context, "筛选", Toast.LENGTH_SHORT).show() }
45 | HeaderViewHolder(view)
46 | }
47 | else -> {
48 | view.setOnClickListener {
49 | Toast.makeText(parent.context, it.tag as String, Toast.LENGTH_SHORT).show()
50 | }
51 | ViewHolder(view)
52 | }
53 | }
54 | }
55 |
56 | override fun getItemViewType(position: Int): Int {
57 | return if (isHome) {
58 | when (position) {
59 | 0 -> R.layout.item_recommend
60 | 1 -> R.layout.item_header
61 | else -> R.layout.item_test
62 | }
63 | } else {
64 | when (position) {
65 | 0 -> R.layout.item_header
66 | else -> R.layout.item_test
67 | }
68 | }
69 | }
70 |
71 | override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
72 | when (holder) {
73 | is RecommendViewHolder -> {
74 | //绑定推荐
75 | }
76 | is HeaderViewHolder -> {
77 | //绑定头数据
78 | }
79 | else -> {
80 | holder?.itemView?.tag = "模拟商品描述$position"
81 | holder?.itemView?.findViewById(R.id.contentTv)?.text = "模拟商品描述$position"
82 | holder?.itemView?.findViewById(R.id.imageView)?.setImageResource(
83 | if (position % 2 == 0) {
84 | R.mipmap.ic_test2
85 | } else {
86 | R.mipmap.ic_test1
87 | }
88 | )
89 | }
90 | }
91 | }
92 |
93 | override fun getItemCount(): Int = 30
94 |
95 | }
96 |
97 | class ViewHolder(view: View) : RecyclerView.ViewHolder(view)
98 | class RecommendViewHolder(view: View) : RecyclerView.ViewHolder(view)
99 | class HeaderViewHolder(view: View) : RecyclerView.ViewHolder(view)
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_recommend.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
15 |
16 |
22 |
23 |
28 |
29 |
34 |
35 |
43 |
44 |
45 |
50 |
51 |
56 |
57 |
62 |
63 |
71 |
72 |
78 |
79 |
80 |
87 |
88 |
93 |
94 |
102 |
103 |
109 |
110 |
111 |
116 |
117 |
122 |
123 |
131 |
132 |
138 |
139 |
140 |
141 |
145 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # 仿饿了么商品列表页面
2 | (ps:其实用什么实现不重要,这里只是为了仿一个UI,闲来写的,希望给新手参考,老司机请绕道)
3 |
4 | ### 首先来看一下饿了么商品列表是什么样子
5 |
6 | 
7 |
8 | ### 1、分析
9 | ①首先是标题栏显示大分类、返回键、搜索键----可用Toolbar实现
10 |
11 | ②展示分类,滑动切换和点击切换,典型的TabLayout
12 |
13 | ③分类列表切换用ViewPager
14 |
15 | ④向上滑动时标题栏隐藏,可使用ScrollView监听滑动,也可以使用CoordinatorLayout加AppBarLayout(推荐)
16 |
17 | ⑤列表用RecyclerView实现,顶部的推荐食品可用不同的ViewType控制
18 |
19 | ⑥列表向上滑动,列表筛选项悬停;可在固定位置放一个默认隐藏的view,筛选项为一个Item,监听滑动,当滑动一定距离后显示View,
20 |
21 | 也可以使用RecyclerView的ItemDecoration绘制该View
22 |
23 | ⑦下拉刷新
24 |
25 | ### 2、动手实现
26 | ①主页面使用CoordinatorLayout+AppBarLayout(ToolBar+SlidingTabLayout)+ViewPager实现,如下是一个很常见的布局
27 |
28 | ```xml
29 |
30 |
34 |
35 |
38 |
39 |
43 |
44 |
47 |
48 |
49 |
52 |
53 |
54 |
55 | ```
56 |
57 | 需要滑动隐藏标题栏是靠app:layout_scrollFlags="scroll|enterAlways",以下为简介,详情请搜索**layout_scrollFlags**
58 |
59 | layout_scrollFlags共有5个属性,需要Child View伴随着滚动事件而滚出或滚进屏幕首先加入"scroll"
60 |
61 | **enterAlways**:快速返回模式。
62 |
63 | **enterAlwaysCollapsed**:enterAlways的附加值,涉及最小高度
64 |
65 | **exitUntilCollapsed**:发生向上滚动事件时,Child View向上滚动退出直至最小高度,然后Scrolling View开始滚动。也就是,Child View不会完全退出屏幕。
66 |
67 | **snap**:Child View滚动比例的一个吸附效果。
68 |
69 | [SlidingTabLayout](https://github.com/H07000223/FlycoTabLayout)是使用别人造好的轮子,使用它很久了很好用很方便,能满足大多数需求,源码也很清晰需要修改也很方便。
70 |
71 | ViewPager设置app:layout_behavior="@string/appbar_scrolling_view_behavior"这是官方提供的behavior,我的理解是约定可滚动View和AppBar的折叠关系,有兴趣可以去研究下源码。
72 |
73 | 然后仅需关联ViewPager和TabLayout即可
74 | ```kotlin
75 | mToolBar = findViewById(R.id.toolbar)
76 | mViewPager = findViewById(R.id.viewPager)
77 | mTabLayout = findViewById(R.id.tabLayout)
78 | mToolBar.title = "下午茶"
79 | mToolBar.setNavigationIcon(R.mipmap.ic_back)
80 | setSupportActionBar(toolbar)
81 | mViewPager.adapter = MyViewPagerAdapter(titles, supportFragmentManager)
82 | mTabLayout.setViewPager(mViewPager)
83 | ```
84 |
85 | ②推荐商品和列表
86 |
87 | 其实这个就很简单了,用过RecyclerView的都知道我们可以用ViewType来使其展示不同的布局
88 |
89 | ```kotlin
90 | override fun getItemViewType(position: Int): Int {
91 | return if (position == 0) {
92 | R.layout.item_recommend //第一个展示推荐商品的布局
93 | } else {
94 | R.layout.item_test //后续展示商品列表项
95 | }
96 | }
97 | ```
98 |
99 | ③上滑筛选项悬停
100 |
101 | 这里我们使用ItemDecoration绘制该View来实现,
102 |
103 | 问:为什么?
104 |
105 | 答:简单啊!
106 |
107 | 问:简单吗?
108 |
109 | 答:简单,因为又有轮子可以用;哈哈,看来我们不生产代码,只是代码的搬运工。
110 |
111 | 这里的实现借用了[StickyRecyclerHeadersDecoration](https://github.com/timehop/sticky-headers-recyclerview)
112 |
113 | 这个库的好处是不用改造RecyclerView就可以轻松实现StickyRecyclerHeaders,平时的城市列表,商品分类也可以用到。
114 |
115 | 首先使你的Adapter实现StickyRecyclerHeadersAdapter,header的布局即为筛选布局
116 | 在实现getHeaderId时将第一个Item的ID返回-1就不会显示,其他商品Item的headerID统一为一个即可,这样在上滑过程中超过position==0筛选即可悬停
117 | ```kotlin
118 | class TestAdapter(private var isHome: Boolean) : RecyclerView.Adapter(), StickyRecyclerHeadersAdapter {
119 |
120 |
121 | override fun onBindHeaderViewHolder(holder: HeaderViewHolder?, position: Int) {
122 |
123 | }
124 |
125 | override fun getHeaderId(position: Int): Long = if (position == 0 && isHome) -1 else 1
126 |
127 | override fun onCreateHeaderViewHolder(parent: ViewGroup?): HeaderViewHolder {
128 | val view = LayoutInflater.from(parent!!.context).inflate(R.layout.item_header, parent, false)
129 | return HeaderViewHolder(view)
130 | }
131 |
132 | override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder {
133 | val view = LayoutInflater.from(parent!!.context).inflate(viewType, parent, false)
134 | return ViewHolder(view)
135 | }
136 |
137 | override fun getItemViewType(position: Int): Int {
138 | return if (position == 0 && isHome) R.layout.item_recommend else R.layout.item_test
139 | }
140 |
141 | override fun onBindViewHolder(holder: ViewHolder?, position: Int) {
142 |
143 | }
144 |
145 | override fun getItemCount(): Int = 30
146 |
147 | }
148 | ```
149 |
150 | ④下拉刷新
151 | 下拉刷新只是模拟实现,并未实现饿了么的动画,Demo中使用的是最近很火的[SmartRefreshLayout](https://github.com/scwang90/SmartRefreshLayout)
152 |
153 | ### 我们来看一下Demo实现的效果
154 |
155 | 
156 |
157 | ### 问题分析
158 |
159 | 实际上头的实现使用ItemDecoration确实比较方便,但是无法实现点击效果。所以达不到筛选的目的,上面的那个粘性头部控件一般只适合那种只做展示的使用,
160 | 最后为了实现这个效果我们使用了[sticky-layoutmanager](https://github.com/qiujayen/sticky-layoutmanager)
161 | 关于上面这个控件的使用大家可以参考原作者的说明。这东西也是上班的时候突然想到此前的这个Demo的点击事件没有完善,所以特来加上这个实现。
162 | [sticky-layoutmanager](https://github.com/qiujayen/sticky-layoutmanager)是更改的layoutmanager所以我们要确定头实际上就是多一个ViewType,实现如下
163 |
164 | ```kotlin
165 | override fun isStickyHeader(position: Int): Boolean {
166 | return if (isHome) {
167 | position == 1
168 | } else {
169 | position == 0
170 | }
171 | }
172 |
173 | override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): RecyclerView.ViewHolder? {
174 | val view = LayoutInflater.from(parent!!.context).inflate(viewType, parent, false)
175 | return when (viewType) {
176 | R.layout.item_recommend -> {
177 | view.setOnClickListener {
178 | Toast.makeText(parent.context, "点击", Toast.LENGTH_SHORT).show()
179 | }
180 | RecommendViewHolder(view)
181 | }
182 | R.layout.item_header -> {
183 | view.findViewById(R.id.type1).setOnClickListener { Toast.makeText(parent.context, "综合排序", Toast.LENGTH_SHORT).show() }
184 | view.findViewById(R.id.type2).setOnClickListener { Toast.makeText(parent.context, "好评优先", Toast.LENGTH_SHORT).show() }
185 | view.findViewById(R.id.type3).setOnClickListener { Toast.makeText(parent.context, "距离最近", Toast.LENGTH_SHORT).show() }
186 | view.findViewById(R.id.type4).setOnClickListener { Toast.makeText(parent.context, "筛选", Toast.LENGTH_SHORT).show() }
187 | HeaderViewHolder(view)
188 | }
189 | else -> {
190 | view.setOnClickListener {
191 | Toast.makeText(parent.context, it.tag as String, Toast.LENGTH_SHORT).show()
192 | }
193 | ViewHolder(view)
194 | }
195 | }
196 | }
197 | ```
198 |
199 | ### 最后我们来看一下增加点击的Demo实现的效果
200 |
201 | 
202 |
--------------------------------------------------------------------------------