├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── drawable
│ │ │ │ ├── ic_my.png
│ │ │ │ ├── ic_cart.png
│ │ │ │ ├── ic_home.png
│ │ │ │ ├── right_go.png
│ │ │ │ ├── ic_category.png
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_sitting.png
│ │ │ │ ├── header_image.png
│ │ │ │ ├── selector_tab.xml
│ │ │ │ ├── shape_oval_red.xml
│ │ │ │ ├── ic_home_black_24dp.xml
│ │ │ │ ├── ic_dashboard_black_24dp.xml
│ │ │ │ ├── ic_notifications_black_24dp.xml
│ │ │ │ └── ic_launcher_background.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── 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
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── attrs.xml
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── layout
│ │ │ │ ├── fragment_fragment1.xml
│ │ │ │ ├── fragment_fragment2.xml
│ │ │ │ ├── fragment_fragment3.xml
│ │ │ │ ├── fragment_fragment4.xml
│ │ │ │ ├── layout_my_tools_header.xml
│ │ │ │ ├── layout_my_count.xml
│ │ │ │ ├── activity_main.xml
│ │ │ │ ├── layout_my_order.xml
│ │ │ │ ├── layout_my_tools.xml
│ │ │ │ ├── layout_my_order_header.xml
│ │ │ │ ├── layout_my_header.xml
│ │ │ │ └── layout_my_balance.xml
│ │ │ ├── menu
│ │ │ │ └── navigation.xml
│ │ │ └── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── yechaoa
│ │ │ │ └── multipleitempage
│ │ │ │ ├── fragment
│ │ │ │ ├── Fragment1.java
│ │ │ │ ├── Fragment2.java
│ │ │ │ ├── Fragment3.java
│ │ │ │ └── Fragment4.java
│ │ │ │ ├── App.java
│ │ │ │ ├── bean
│ │ │ │ └── MultipleItem.java
│ │ │ │ ├── MainActivity.java
│ │ │ │ ├── adapter
│ │ │ │ └── MultipleItemQuickAdapter.java
│ │ │ │ └── widget
│ │ │ │ └── CircleImageView.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── yechaoa
│ │ │ └── multipleitempage
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── yechaoa
│ │ └── multipleitempage
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── gif
├── multiple_item_page.gif
└── multiple_item_page.png
├── .idea
├── dictionaries
│ └── yechao.xml
├── vcs.xml
├── modules.xml
├── runConfigurations.xml
├── gradle.xml
└── misc.xml
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── gradle.properties
├── gradlew.bat
├── gradlew
├── LICENSE
└── README.md
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/gif/multiple_item_page.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yechaoa/MultipleItemPage/HEAD/gif/multiple_item_page.gif
--------------------------------------------------------------------------------
/gif/multiple_item_page.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yechaoa/MultipleItemPage/HEAD/gif/multiple_item_page.png
--------------------------------------------------------------------------------
/.idea/dictionaries/yechao.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yechaoa/MultipleItemPage/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_my.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yechaoa/MultipleItemPage/HEAD/app/src/main/res/drawable/ic_my.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_cart.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yechaoa/MultipleItemPage/HEAD/app/src/main/res/drawable/ic_cart.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_home.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yechaoa/MultipleItemPage/HEAD/app/src/main/res/drawable/ic_home.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/right_go.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yechaoa/MultipleItemPage/HEAD/app/src/main/res/drawable/right_go.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_category.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yechaoa/MultipleItemPage/HEAD/app/src/main/res/drawable/ic_category.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yechaoa/MultipleItemPage/HEAD/app/src/main/res/drawable/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_sitting.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yechaoa/MultipleItemPage/HEAD/app/src/main/res/drawable/ic_sitting.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/header_image.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yechaoa/MultipleItemPage/HEAD/app/src/main/res/drawable/header_image.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yechaoa/MultipleItemPage/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yechaoa/MultipleItemPage/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yechaoa/MultipleItemPage/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yechaoa/MultipleItemPage/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yechaoa/MultipleItemPage/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yechaoa/MultipleItemPage/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/yechaoa/MultipleItemPage/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/yechaoa/MultipleItemPage/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/yechaoa/MultipleItemPage/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/yechaoa/MultipleItemPage/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 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat Dec 16 20:52:48 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-4.1-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | MultipleItemPage
3 | 首页
4 | 分类
5 | 购物车
6 | 我的
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/selector_tab.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/shape_oval_red.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_home_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_dashboard_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #1296db
4 | #1296db
5 | #1296db
6 |
7 | #ffffff
8 | #E4E4E4
9 | #E4E4E4
10 | #ff0000
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_fragment1.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_fragment2.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_fragment3.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/test/java/com/yechaoa/multipleitempage/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.yechaoa.multipleitempage;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_fragment4.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_notifications_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yechaoa/multipleitempage/fragment/Fragment1.java:
--------------------------------------------------------------------------------
1 | package com.yechaoa.multipleitempage.fragment;
2 |
3 | import android.os.Bundle;
4 | import android.support.v4.app.Fragment;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 |
9 | import com.yechaoa.multipleitempage.R;
10 |
11 | public class Fragment1 extends Fragment {
12 |
13 | @Override
14 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
15 | return inflater.inflate(R.layout.fragment_fragment1, container, false);
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yechaoa/multipleitempage/fragment/Fragment2.java:
--------------------------------------------------------------------------------
1 | package com.yechaoa.multipleitempage.fragment;
2 |
3 | import android.os.Bundle;
4 | import android.support.v4.app.Fragment;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 |
9 | import com.yechaoa.multipleitempage.R;
10 |
11 | public class Fragment2 extends Fragment {
12 |
13 | @Override
14 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
15 | return inflater.inflate(R.layout.fragment_fragment2, container, false);
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yechaoa/multipleitempage/fragment/Fragment3.java:
--------------------------------------------------------------------------------
1 | package com.yechaoa.multipleitempage.fragment;
2 |
3 | import android.os.Bundle;
4 | import android.support.v4.app.Fragment;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 |
9 | import com.yechaoa.multipleitempage.R;
10 |
11 | public class Fragment3 extends Fragment {
12 |
13 | @Override
14 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
15 | return inflater.inflate(R.layout.fragment_fragment3, container, false);
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yechaoa/multipleitempage/App.java:
--------------------------------------------------------------------------------
1 | package com.yechaoa.multipleitempage;
2 |
3 | import android.app.Application;
4 |
5 | import com.yechaoa.yutils.ActivityUtil;
6 | import com.yechaoa.yutils.LogUtil;
7 | import com.yechaoa.yutils.YUtils;
8 |
9 | /**
10 | * Created by yechao on 2017/12/16.
11 | * Describe :
12 | */
13 | public class App extends Application {
14 |
15 | @Override
16 | public void onCreate() {
17 | super.onCreate();
18 |
19 | YUtils.initialize(this);
20 | LogUtil.setIsLog(true);
21 | registerActivityLifecycleCallbacks(ActivityUtil.getActivityLifecycleCallbacks());
22 |
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/navigation.xml:
--------------------------------------------------------------------------------
1 |
2 |
24 |
--------------------------------------------------------------------------------
/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 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_my_tools_header.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
15 |
16 |
20 |
21 |
--------------------------------------------------------------------------------
/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 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/yechaoa/multipleitempage/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.yechaoa.multipleitempage;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.yechaoa.multipleitempage", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_my_count.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
15 |
16 |
24 |
25 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
16 |
17 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yechaoa/multipleitempage/bean/MultipleItem.java:
--------------------------------------------------------------------------------
1 | package com.yechaoa.multipleitempage.bean;
2 |
3 | import com.chad.library.adapter.base.entity.MultiItemEntity;
4 |
5 | /**
6 | * Created by yechao on 2017/12/15.
7 | * Describe :
8 | */
9 |
10 | public class MultipleItem implements MultiItemEntity {
11 |
12 | public static final int TYPE_COUNT = 1;
13 | public static final int TYPE_ORDER_HEADER = 2;
14 | public static final int TYPE_ORDER = 3;
15 | public static final int TYPE_BALANCE = 4;
16 | public static final int TYPE_TOOLS_HEADER = 5;
17 | public static final int TYPE_TOOLS = 6;
18 | private int itemType;
19 | private int spanSize;
20 |
21 | public MultipleItem(int itemType, int spanSize) {
22 | this.itemType = itemType;
23 | this.spanSize = spanSize;
24 | }
25 |
26 | @Override
27 | public int getItemType() {
28 | return itemType;
29 | }
30 |
31 | public int getSpanSize() {
32 | return spanSize;
33 | }
34 |
35 | public void setSpanSize(int spanSize) {
36 | this.spanSize = spanSize;
37 | }
38 |
39 |
40 | public String mString1;
41 |
42 | public String mString2;
43 |
44 | public boolean isShow;
45 |
46 | public int count;
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 26
5 | defaultConfig {
6 | applicationId "com.yechaoa.multipleitempage"
7 | minSdkVersion 16
8 | targetSdkVersion 26
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 | vectorDrawables.useSupportLibrary= true
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | implementation fileTree(dir: 'libs', include: ['*.jar'])
24 | implementation 'com.android.support:appcompat-v7:26.1.0'
25 | implementation 'com.android.support:design:26.1.0'
26 | implementation 'com.android.support.constraint:constraint-layout:1.0.2'
27 | implementation 'com.android.support:support-vector-drawable:26.1.0'
28 | testImplementation 'junit:junit:4.12'
29 | androidTestImplementation 'com.android.support.test:runner:1.0.1'
30 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
31 |
32 | compile 'com.github.yechaoa:YUtils:2.0.6'
33 | compile 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.34'
34 | }
35 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_my_order.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
18 |
19 |
27 |
28 |
39 |
40 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_my_tools.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
18 |
19 |
27 |
28 |
39 |
40 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_my_order_header.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
18 |
19 |
25 |
26 |
32 |
33 |
39 |
40 |
41 |
42 |
46 |
47 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_my_header.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
18 |
19 |
26 |
27 |
33 |
34 |
40 |
41 |
42 |
43 |
50 |
51 |
--------------------------------------------------------------------------------
/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/res/layout/layout_my_balance.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
15 |
16 |
20 |
21 |
26 |
27 |
33 |
34 |
38 |
39 |
44 |
45 |
46 |
47 |
51 |
52 |
58 |
59 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 | Android
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | $USER_HOME$/.subversion
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yechaoa/multipleitempage/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.yechaoa.multipleitempage;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.NonNull;
5 | import android.support.design.widget.BottomNavigationView;
6 | import android.support.v4.app.Fragment;
7 | import android.support.v4.app.FragmentManager;
8 | import android.support.v4.app.FragmentPagerAdapter;
9 | import android.support.v4.view.ViewPager;
10 | import android.support.v7.app.AppCompatActivity;
11 | import android.view.MenuItem;
12 |
13 | import com.yechaoa.multipleitempage.fragment.Fragment1;
14 | import com.yechaoa.multipleitempage.fragment.Fragment2;
15 | import com.yechaoa.multipleitempage.fragment.Fragment3;
16 | import com.yechaoa.multipleitempage.fragment.Fragment4;
17 |
18 | public class MainActivity extends AppCompatActivity {
19 |
20 | private ViewPager mViewPager;
21 | private BottomNavigationView mNavigation;
22 |
23 | @Override
24 | protected void onCreate(Bundle savedInstanceState) {
25 | super.onCreate(savedInstanceState);
26 | setContentView(R.layout.activity_main);
27 |
28 | mNavigation = findViewById(R.id.navigation);
29 | mViewPager = findViewById(R.id.viewPager);
30 | mViewPager.setAdapter(new SimpleFragmentPagerAdapter(getSupportFragmentManager()));
31 | mViewPager.addOnPageChangeListener(mOnPageChangeListener);
32 | mNavigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
33 | }
34 |
35 | private ViewPager.OnPageChangeListener mOnPageChangeListener = new ViewPager.OnPageChangeListener() {
36 | @Override
37 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
38 |
39 | }
40 |
41 | @Override
42 | public void onPageSelected(int position) {
43 | mNavigation.getMenu().getItem(position).setChecked(true);
44 | }
45 |
46 | @Override
47 | public void onPageScrollStateChanged(int state) {
48 |
49 | }
50 | };
51 |
52 |
53 | private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
54 | = new BottomNavigationView.OnNavigationItemSelectedListener() {
55 |
56 | @Override
57 | public boolean onNavigationItemSelected(@NonNull MenuItem item) {
58 | switch (item.getItemId()) {
59 | case R.id.navigation_home:
60 | mViewPager.setCurrentItem(0);
61 | return true;
62 | case R.id.navigation_category:
63 | mViewPager.setCurrentItem(1);
64 | return true;
65 | case R.id.navigation_cart:
66 | mViewPager.setCurrentItem(2);
67 | return true;
68 | case R.id.navigation_my:
69 | mViewPager.setCurrentItem(3);
70 | return true;
71 | }
72 | return false;
73 | }
74 | };
75 |
76 |
77 | private class SimpleFragmentPagerAdapter extends FragmentPagerAdapter {
78 |
79 | private Fragment[] mFragment = new Fragment[]{new Fragment1(), new Fragment2(), new Fragment3(), new Fragment4()};
80 |
81 | private SimpleFragmentPagerAdapter(FragmentManager fm) {
82 | super(fm);
83 | }
84 |
85 | @Override
86 | public Fragment getItem(int position) {
87 | return mFragment[position];
88 | }
89 |
90 | @Override
91 | public int getCount() {
92 | return mFragment.length;
93 | }
94 |
95 | }
96 |
97 |
98 | }
99 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yechaoa/multipleitempage/adapter/MultipleItemQuickAdapter.java:
--------------------------------------------------------------------------------
1 | package com.yechaoa.multipleitempage.adapter;
2 |
3 | import android.support.v4.content.ContextCompat;
4 | import android.view.View;
5 |
6 | import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
7 | import com.chad.library.adapter.base.BaseViewHolder;
8 | import com.yechaoa.multipleitempage.R;
9 | import com.yechaoa.multipleitempage.bean.MultipleItem;
10 |
11 | import java.util.List;
12 |
13 | /**
14 | * Created by yechao on 2017/12/15.
15 | * Describe :
16 | */
17 |
18 | public class MultipleItemQuickAdapter extends BaseMultiItemQuickAdapter {
19 |
20 | public MultipleItemQuickAdapter(List data) {
21 | super(data);
22 | addItemType(MultipleItem.TYPE_COUNT, R.layout.layout_my_count);
23 | addItemType(MultipleItem.TYPE_ORDER_HEADER, R.layout.layout_my_order_header);
24 | addItemType(MultipleItem.TYPE_ORDER, R.layout.layout_my_order);
25 | addItemType(MultipleItem.TYPE_BALANCE, R.layout.layout_my_balance);
26 | addItemType(MultipleItem.TYPE_TOOLS_HEADER, R.layout.layout_my_tools_header);
27 | addItemType(MultipleItem.TYPE_TOOLS, R.layout.layout_my_tools);
28 | }
29 |
30 | @Override
31 | protected void convert(BaseViewHolder helper, MultipleItem item) {
32 | switch (helper.getItemViewType()) {
33 | case MultipleItem.TYPE_COUNT:
34 | helper.setText(R.id.my_favorites, item.mString1).addOnClickListener(R.id.my_favorites);
35 | helper.setText(R.id.my_bands, item.mString2).addOnClickListener(R.id.my_bands);
36 | break;
37 | case MultipleItem.TYPE_ORDER_HEADER:
38 | helper.addOnClickListener(R.id.ll_my_order);
39 | break;
40 | case MultipleItem.TYPE_ORDER:
41 | helper.setImageDrawable(R.id.my_order_image, ContextCompat.getDrawable(mContext, R.drawable.ic_launcher));
42 | helper.setText(R.id.my_order_name, item.mString1);
43 | if (item.isShow) {
44 | helper.getView(R.id.my_order_count).setVisibility(View.VISIBLE);
45 | if (item.count > 0) {
46 | if (item.count < 99) {
47 | helper.setText(R.id.my_order_count, String.valueOf(item.count));
48 | } else {
49 | helper.setText(R.id.my_order_count, String.valueOf("99+"));
50 | }
51 | } else {
52 | helper.getView(R.id.my_order_count).setVisibility(View.GONE);
53 | }
54 | } else {
55 | helper.getView(R.id.my_order_count).setVisibility(View.GONE);
56 | }
57 | break;
58 | case MultipleItem.TYPE_BALANCE:
59 | helper.setText(R.id.my_balance_text, item.mString1);
60 | helper.addOnClickListener(R.id.my_balance_btn);
61 | break;
62 | case MultipleItem.TYPE_TOOLS_HEADER:
63 | //helper.setText(R.id.tv_item_name, item.mString1);
64 | break;
65 | case MultipleItem.TYPE_TOOLS:
66 | helper.setImageDrawable(R.id.my_tools_image, ContextCompat.getDrawable(mContext, R.drawable.ic_launcher));
67 | helper.setText(R.id.my_tools_text, item.mString1);
68 | if (item.isShow) {
69 | helper.getView(R.id.my_tools_count).setVisibility(View.VISIBLE);
70 | if (item.count > 0) {
71 | if (item.count < 99) {
72 | helper.setText(R.id.my_tools_count, String.valueOf(item.count));
73 | } else {
74 | helper.setText(R.id.my_tools_count, String.valueOf("99+"));
75 | }
76 | } else {
77 | helper.getView(R.id.my_tools_count).setVisibility(View.GONE);
78 | }
79 | } else {
80 | helper.getView(R.id.my_tools_count).setVisibility(View.GONE);
81 | }
82 | break;
83 | }
84 | }
85 |
86 | }
87 |
--------------------------------------------------------------------------------
/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/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 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yechaoa/multipleitempage/widget/CircleImageView.java:
--------------------------------------------------------------------------------
1 | package com.yechaoa.multipleitempage.widget;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.Bitmap;
6 | import android.graphics.BitmapShader;
7 | import android.graphics.Canvas;
8 | import android.graphics.Color;
9 | import android.graphics.Matrix;
10 | import android.graphics.Paint;
11 | import android.graphics.RectF;
12 | import android.graphics.Shader;
13 | import android.graphics.drawable.BitmapDrawable;
14 | import android.graphics.drawable.ColorDrawable;
15 | import android.graphics.drawable.Drawable;
16 | import android.util.AttributeSet;
17 | import android.widget.ImageView;
18 |
19 | import com.yechaoa.multipleitempage.R;
20 |
21 | public class CircleImageView extends ImageView {
22 |
23 | private static final ScaleType SCALE_TYPE = ScaleType.CENTER_CROP;
24 |
25 | private static final Bitmap.Config BITMAP_CONFIG = Bitmap.Config.ARGB_8888;
26 | private static final int COLORDRAWABLE_DIMENSION = 1;
27 |
28 | private static final int DEFAULT_BORDER_WIDTH = 0;
29 | private static final int DEFAULT_BORDER_COLOR = Color.BLACK;
30 |
31 | private final RectF mDrawableRect = new RectF();
32 | private final RectF mBorderRect = new RectF();
33 |
34 | private final Matrix mShaderMatrix = new Matrix();
35 | private final Paint mBitmapPaint = new Paint();
36 | private final Paint mBorderPaint = new Paint();
37 |
38 | private int mBorderColor = DEFAULT_BORDER_COLOR;
39 | private int mBorderWidth = DEFAULT_BORDER_WIDTH;
40 |
41 | private Bitmap mBitmap;
42 | private BitmapShader mBitmapShader;
43 | private int mBitmapWidth;
44 | private int mBitmapHeight;
45 |
46 | private float mDrawableRadius;
47 | private float mBorderRadius;
48 |
49 | private boolean mReady;
50 | private boolean mSetupPending;
51 |
52 | public CircleImageView(Context context) {
53 | super(context);
54 | }
55 |
56 | public CircleImageView(Context context, AttributeSet attrs) {
57 | this(context, attrs, 0);
58 | }
59 |
60 | public CircleImageView(Context context, AttributeSet attrs, int defStyle) {
61 | super(context, attrs, defStyle);
62 | super.setScaleType(SCALE_TYPE);
63 |
64 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CircleImageView, defStyle, 0);
65 |
66 | mBorderWidth = a.getDimensionPixelSize(R.styleable.CircleImageView_border_width, DEFAULT_BORDER_WIDTH);
67 | mBorderColor = a.getColor(R.styleable.CircleImageView_border_color, DEFAULT_BORDER_COLOR);
68 |
69 | a.recycle();
70 |
71 | mReady = true;
72 |
73 | if (mSetupPending) {
74 | setup();
75 | mSetupPending = false;
76 | }
77 | }
78 |
79 | @Override
80 | public ScaleType getScaleType() {
81 | return SCALE_TYPE;
82 | }
83 |
84 | @Override
85 | public void setScaleType(ScaleType scaleType) {
86 | if (scaleType != SCALE_TYPE) {
87 | throw new IllegalArgumentException(String.format("ScaleType %s not supported.", scaleType));
88 | }
89 | }
90 |
91 | @Override
92 | protected void onDraw(Canvas canvas) {
93 | if (getDrawable() == null) {
94 | return;
95 | }
96 |
97 | canvas.drawCircle(getWidth() / 2, getHeight() / 2, mDrawableRadius, mBitmapPaint);
98 | canvas.drawCircle(getWidth() / 2, getHeight() / 2, mBorderRadius, mBorderPaint);
99 | }
100 |
101 | @Override
102 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
103 | super.onSizeChanged(w, h, oldw, oldh);
104 | setup();
105 | }
106 |
107 | public int getBorderColor() {
108 | return mBorderColor;
109 | }
110 |
111 | public void setBorderColor(int borderColor) {
112 | if (borderColor == mBorderColor) {
113 | return;
114 | }
115 |
116 | mBorderColor = borderColor;
117 | mBorderPaint.setColor(mBorderColor);
118 | invalidate();
119 | }
120 |
121 | public int getBorderWidth() {
122 | return mBorderWidth;
123 | }
124 |
125 | public void setBorderWidth(int borderWidth) {
126 | if (borderWidth == mBorderWidth) {
127 | return;
128 | }
129 |
130 | mBorderWidth = borderWidth;
131 | setup();
132 | }
133 |
134 | @Override
135 | public void setImageBitmap(Bitmap bm) {
136 | super.setImageBitmap(bm);
137 | mBitmap = bm;
138 | setup();
139 | }
140 |
141 | @Override
142 | public void setImageDrawable(Drawable drawable) {
143 | super.setImageDrawable(drawable);
144 | mBitmap = getBitmapFromDrawable(drawable);
145 | setup();
146 | }
147 |
148 | @Override
149 | public void setImageResource(int resId) {
150 | super.setImageResource(resId);
151 | mBitmap = getBitmapFromDrawable(getDrawable());
152 | setup();
153 | }
154 |
155 | private Bitmap getBitmapFromDrawable(Drawable drawable) {
156 | if (drawable == null) {
157 | return null;
158 | }
159 |
160 | if (drawable instanceof BitmapDrawable) {
161 | return ((BitmapDrawable) drawable).getBitmap();
162 | }
163 |
164 | try {
165 | Bitmap bitmap;
166 |
167 | if (drawable instanceof ColorDrawable) {
168 | bitmap = Bitmap.createBitmap(COLORDRAWABLE_DIMENSION, COLORDRAWABLE_DIMENSION, BITMAP_CONFIG);
169 | } else {
170 | bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), BITMAP_CONFIG);
171 | }
172 |
173 | Canvas canvas = new Canvas(bitmap);
174 | drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
175 | drawable.draw(canvas);
176 | return bitmap;
177 | } catch (OutOfMemoryError e) {
178 | return null;
179 | }
180 | }
181 |
182 | private void setup() {
183 | if (!mReady) {
184 | mSetupPending = true;
185 | return;
186 | }
187 |
188 | if (mBitmap == null) {
189 | return;
190 | }
191 |
192 | mBitmapShader = new BitmapShader(mBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
193 |
194 | mBitmapPaint.setAntiAlias(true);
195 | mBitmapPaint.setShader(mBitmapShader);
196 |
197 | mBorderPaint.setStyle(Paint.Style.STROKE);
198 | mBorderPaint.setAntiAlias(true);
199 | mBorderPaint.setColor(mBorderColor);
200 | mBorderPaint.setStrokeWidth(mBorderWidth);
201 |
202 | mBitmapHeight = mBitmap.getHeight();
203 | mBitmapWidth = mBitmap.getWidth();
204 |
205 | mBorderRect.set(0, 0, getWidth(), getHeight());
206 | mBorderRadius = Math.min((mBorderRect.height() - mBorderWidth) / 2, (mBorderRect.width() - mBorderWidth) / 2);
207 |
208 | mDrawableRect.set(mBorderWidth, mBorderWidth, mBorderRect.width() - mBorderWidth, mBorderRect.height() - mBorderWidth);
209 | mDrawableRadius = Math.min(mDrawableRect.height() / 2, mDrawableRect.width() / 2);
210 |
211 | updateShaderMatrix();
212 | invalidate();
213 | }
214 |
215 | private void updateShaderMatrix() {
216 | float scale;
217 | float dx = 0;
218 | float dy = 0;
219 |
220 | mShaderMatrix.set(null);
221 |
222 | if (mBitmapWidth * mDrawableRect.height() > mDrawableRect.width() * mBitmapHeight) {
223 | scale = mDrawableRect.height() / (float) mBitmapHeight;
224 | dx = (mDrawableRect.width() - mBitmapWidth * scale) * 0.5f;
225 | } else {
226 | scale = mDrawableRect.width() / (float) mBitmapWidth;
227 | dy = (mDrawableRect.height() - mBitmapHeight * scale) * 0.5f;
228 | }
229 |
230 | mShaderMatrix.setScale(scale, scale);
231 | mShaderMatrix.postTranslate((int) (dx + 0.5f) + mBorderWidth, (int) (dy + 0.5f) + mBorderWidth);
232 |
233 | mBitmapShader.setLocalMatrix(mShaderMatrix);
234 | }
235 |
236 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/yechaoa/multipleitempage/fragment/Fragment4.java:
--------------------------------------------------------------------------------
1 | package com.yechaoa.multipleitempage.fragment;
2 |
3 | import android.os.Bundle;
4 | import android.os.Handler;
5 | import android.support.v4.app.Fragment;
6 | import android.support.v4.widget.SwipeRefreshLayout;
7 | import android.support.v7.widget.GridLayoutManager;
8 | import android.support.v7.widget.LinearLayoutManager;
9 | import android.support.v7.widget.RecyclerView;
10 | import android.view.LayoutInflater;
11 | import android.view.View;
12 | import android.view.ViewGroup;
13 | import android.widget.ImageView;
14 | import android.widget.TextView;
15 |
16 | import com.chad.library.adapter.base.BaseQuickAdapter;
17 | import com.yechaoa.multipleitempage.R;
18 | import com.yechaoa.multipleitempage.adapter.MultipleItemQuickAdapter;
19 | import com.yechaoa.multipleitempage.bean.MultipleItem;
20 | import com.yechaoa.multipleitempage.widget.CircleImageView;
21 | import com.yechaoa.yutils.LogUtil;
22 | import com.yechaoa.yutils.YUtils;
23 |
24 | import java.util.ArrayList;
25 | import java.util.List;
26 |
27 | public class Fragment4 extends Fragment {
28 |
29 | private SwipeRefreshLayout mSwipeRefreshLayout;
30 | private RecyclerView mRecyclerView;
31 |
32 | private MultipleItem multipleItem = null;
33 |
34 | private List itemDataList;
35 |
36 | private MultipleItemQuickAdapter multipleItemQuickAdapter;
37 |
38 | @Override
39 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
40 | return inflater.inflate(R.layout.fragment_fragment4, container, false);
41 | }
42 |
43 | @Override
44 | public void onStart() {
45 | super.onStart();
46 |
47 | mSwipeRefreshLayout = getActivity().findViewById(R.id.swipeRefreshLayout);
48 | mRecyclerView = getActivity().findViewById(R.id.recyclerView);
49 |
50 | initSwipeRefreshLayout();
51 |
52 | initItemData();
53 |
54 | initRecyclerView();
55 |
56 | initListener();
57 |
58 | }
59 |
60 |
61 | private void initSwipeRefreshLayout() {
62 | mSwipeRefreshLayout.setColorSchemeResources(
63 | android.R.color.holo_blue_bright,
64 | android.R.color.holo_green_light,
65 | android.R.color.holo_orange_light);
66 |
67 | mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
68 | @Override
69 | public void onRefresh() {
70 | new Handler().postDelayed(new Runnable() {
71 | @Override
72 | public void run() {
73 | multipleItemQuickAdapter.notifyDataSetChanged();
74 | mSwipeRefreshLayout.setRefreshing(false);
75 | YUtils.showToast("刷新完成");
76 | }
77 | }, 2000);
78 | }
79 | });
80 | }
81 |
82 |
83 | private void initItemData() {
84 | itemDataList = new ArrayList<>();
85 |
86 | multipleItem = new MultipleItem(MultipleItem.TYPE_COUNT, 5);
87 | multipleItem.mString1 = "收藏";
88 | multipleItem.mString2 = "关注";
89 | itemDataList.add(multipleItem);
90 |
91 | multipleItem = new MultipleItem(MultipleItem.TYPE_ORDER_HEADER, 5);
92 | multipleItem.mString2 = "type2";
93 | itemDataList.add(multipleItem);
94 |
95 | for (int i = 0; i < 5; i++) {
96 | multipleItem = new MultipleItem(MultipleItem.TYPE_ORDER, 1);
97 | multipleItem.mString1 = "待付款";
98 | if (i % 2 == 0) {
99 | multipleItem.isShow = true;
100 | multipleItem.count = 6;
101 | } else {
102 | multipleItem.isShow = false;
103 | multipleItem.count = 0;
104 | }
105 | itemDataList.add(multipleItem);
106 | }
107 |
108 | multipleItem = new MultipleItem(MultipleItem.TYPE_BALANCE, 5);
109 | multipleItem.mString1 = "¥9999.00";
110 | itemDataList.add(multipleItem);
111 |
112 | multipleItem = new MultipleItem(MultipleItem.TYPE_TOOLS_HEADER, 5);
113 | multipleItem.mString1 = "type5";
114 | itemDataList.add(multipleItem);
115 |
116 | for (int i = 0; i < 5; i++) {
117 | multipleItem = new MultipleItem(MultipleItem.TYPE_TOOLS, 1);
118 | multipleItem.mString1 = "使用帮助";
119 | if (i % 2 == 0) {
120 | multipleItem.isShow = true;
121 | multipleItem.count = 100;
122 | } else {
123 | multipleItem.isShow = false;
124 | multipleItem.count = 0;
125 | }
126 | itemDataList.add(multipleItem);
127 | }
128 | }
129 |
130 |
131 | private void initRecyclerView() {
132 | GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(), 5);
133 | mRecyclerView.setLayoutManager(gridLayoutManager);
134 |
135 | multipleItemQuickAdapter = new MultipleItemQuickAdapter(itemDataList);
136 |
137 | View headerView = getHeaderView(new View.OnClickListener() {
138 | @Override
139 | public void onClick(View view) {
140 | switch (view.getId()) {
141 | case R.id.my_header_image:
142 | YUtils.showToast("你点击了头像");
143 | break;
144 | case R.id.my_header_settings:
145 | YUtils.showToast("你点击了设置");
146 | break;
147 | }
148 | }
149 | });
150 |
151 | multipleItemQuickAdapter.addHeaderView(headerView);
152 |
153 | mRecyclerView.setAdapter(multipleItemQuickAdapter);
154 | }
155 |
156 |
157 | private View getHeaderView(View.OnClickListener listener) {
158 | View headerView = getLayoutInflater().inflate(R.layout.layout_my_header, (ViewGroup) mRecyclerView.getParent(), false);
159 |
160 | CircleImageView myHeaderImage = headerView.findViewById(R.id.my_header_image);
161 | myHeaderImage.setImageResource(R.drawable.header_image);
162 | myHeaderImage.setOnClickListener(listener);
163 |
164 | TextView myHeaderName = headerView.findViewById(R.id.my_header_name);
165 | myHeaderName.setText("名字");
166 |
167 | TextView myHeaderMobile = headerView.findViewById(R.id.my_header_mobile);
168 | myHeaderMobile.setText("手机号");
169 |
170 | ImageView myHeaderSettings = headerView.findViewById(R.id.my_header_settings);
171 | myHeaderSettings.setOnClickListener(listener);
172 |
173 | return headerView;
174 | }
175 |
176 |
177 | private void initListener() {
178 | multipleItemQuickAdapter.setSpanSizeLookup(new BaseQuickAdapter.SpanSizeLookup() {
179 | @Override
180 | public int getSpanSize(GridLayoutManager gridLayoutManager, int position) {
181 | return itemDataList.get(position).getSpanSize();
182 | }
183 | });
184 |
185 | multipleItemQuickAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
186 | @Override
187 | public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
188 |
189 | YUtils.showToast("第 " + position);
190 |
191 | //可以再加一层 类型 的判断,一般来说订单不是点了就消失的
192 | if (itemDataList.get(position).getItemType() == MultipleItem.TYPE_TOOLS) {
193 | if (itemDataList.get(position).isShow) {
194 | itemDataList.get(position).isShow = false;
195 | LogUtil.i("count = " + itemDataList.get(position).count);
196 | multipleItemQuickAdapter.notifyItemChanged(position + 1);
197 | } else
198 | itemDataList.get(position).isShow = false;
199 | }
200 |
201 | }
202 | });
203 |
204 | multipleItemQuickAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
205 | @Override
206 | public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
207 | switch (view.getId()) {
208 | case R.id.my_favorites:
209 | YUtils.showToast("收藏");
210 | break;
211 | case R.id.my_bands:
212 | YUtils.showToast("关注");
213 | break;
214 | case R.id.ll_my_order:
215 | YUtils.showToast("全部订单");
216 | break;
217 | case R.id.my_balance_btn:
218 | YUtils.showToast("立即充值");
219 | break;
220 | }
221 | }
222 | });
223 |
224 | }
225 |
226 | }
227 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # MultipleItemPage
2 | RecyclerView多布局,“我的”、“个人中心” 页面经典写法
3 |
4 | #### 效果:
5 |
6 | 
7 | 
8 |
9 |
10 |
11 |
12 | > 多布局的使用场景还是蛮多的,比如“首页”、“我的”等页面,早期的时候大家一般都是拼起来的,后来开始自定义ListView(支付宝现在的首页还是ListView),再到后来的RecyclerView。
13 | >
14 | > 其实多布局都是一个套路,根据类型去引入layout,本文以RecyclerView为例,以BaseRecyclerViewAdapterHelper为辅演示多布局的写法。
15 |
16 |
17 |
18 | ### 1.添加依赖
19 |
20 | > compile 'com.github.yechaoa:YUtils:2.0.6'
21 | compile 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.34'
22 |
23 | YUtils是一个快速开发工具集合,感兴趣的可以戳 [YUtils](https://github.com/yechaoa/YUtils)
24 |
25 |
26 |
27 | ### 2.主页面
28 |
29 | #### 主页面采用的是 ViewPager + BottomNavigationView
30 |
31 | > 稍微过一下吧。。不想看的直接跳到第3步
32 |
33 |
34 |
35 | #### 布局:
36 |
37 | ```
38 |
39 |
47 |
48 |
53 |
54 |
61 |
62 |
63 | ```
64 |
65 |
66 | #### 添加Listener让二者关联起来
67 |
68 | ```
69 | mViewPager.addOnPageChangeListener(mOnPageChangeListener);
70 | mNavigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
71 | ```
72 |
73 | ```
74 | private ViewPager.OnPageChangeListener mOnPageChangeListener = new ViewPager.OnPageChangeListener() {
75 | @Override
76 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
77 |
78 | }
79 |
80 | @Override
81 | public void onPageSelected(int position) {
82 | mNavigation.getMenu().getItem(position).setChecked(true);
83 | }
84 |
85 | @Override
86 | public void onPageScrollStateChanged(int state) {
87 |
88 | }
89 | };
90 |
91 |
92 | private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
93 | = new BottomNavigationView.OnNavigationItemSelectedListener() {
94 |
95 | @Override
96 | public boolean onNavigationItemSelected(@NonNull MenuItem item) {
97 | switch (item.getItemId()) {
98 | case R.id.navigation_home:
99 | mViewPager.setCurrentItem(0);
100 | return true;
101 | case R.id.navigation_category:
102 | mViewPager.setCurrentItem(1);
103 | return true;
104 | case R.id.navigation_cart:
105 | mViewPager.setCurrentItem(2);
106 | return true;
107 | case R.id.navigation_my:
108 | mViewPager.setCurrentItem(3);
109 | return true;
110 | }
111 | return false;
112 | }
113 | };
114 | ```
115 |
116 | > ViewPager选中的时候让BottomNavigationView的item也选中,BottomNavigationView的item选中的时候让ViewPager切换page
117 |
118 |
119 |
120 | ### 3.Fragment(“我的”页面)
121 |
122 | #### 布局,SwipeRefreshLayout(下拉刷新)嵌套RecyclerView:
123 |
124 | ```
125 |
129 |
130 |
134 |
135 |
136 |
137 | ```
138 |
139 |
140 | #### 初始化Data
141 |
142 | ```
143 | private void initItemData() {
144 | itemDataList = new ArrayList<>();
145 |
146 | multipleItem = new MultipleItem(MultipleItem.TYPE_COUNT, 5);
147 | multipleItem.mString1 = "收藏";
148 | multipleItem.mString2 = "关注";
149 | itemDataList.add(multipleItem);
150 |
151 | multipleItem = new MultipleItem(MultipleItem.TYPE_ORDER_HEADER, 5);
152 | multipleItem.mString2 = "type2";
153 | itemDataList.add(multipleItem);
154 |
155 | for (int i = 0; i < 5; i++) {
156 | multipleItem = new MultipleItem(MultipleItem.TYPE_ORDER, 1);
157 | multipleItem.mString1 = "待付款";
158 | if (i % 2 == 0) {
159 | multipleItem.isShow = true;
160 | multipleItem.count = 6;
161 | } else {
162 | multipleItem.isShow = false;
163 | multipleItem.count = 0;
164 | }
165 | itemDataList.add(multipleItem);
166 | }
167 |
168 | multipleItem = new MultipleItem(MultipleItem.TYPE_BALANCE, 5);
169 | multipleItem.mString1 = "¥9999.00";
170 | itemDataList.add(multipleItem);
171 |
172 | multipleItem = new MultipleItem(MultipleItem.TYPE_TOOLS_HEADER, 5);
173 | multipleItem.mString1 = "type5";
174 | itemDataList.add(multipleItem);
175 |
176 | for (int i = 0; i < 5; i++) {
177 | multipleItem = new MultipleItem(MultipleItem.TYPE_TOOLS, 1);
178 | multipleItem.mString1 = "使用帮助";
179 | if (i % 2 == 0) {
180 | multipleItem.isShow = true;
181 | multipleItem.count = 100;
182 | } else {
183 | multipleItem.isShow = false;
184 | multipleItem.count = 0;
185 | }
186 | itemDataList.add(multipleItem);
187 | }
188 | }
189 | ```
190 |
191 |
192 | #### 获取id
193 |
194 | ```
195 | mSwipeRefreshLayout = getActivity().findViewById(R.id.swipeRefreshLayout);
196 | mRecyclerView = getActivity().findViewById(R.id.recyclerView);
197 | ```
198 |
199 |
200 | #### 初始化SwipeRefreshLayout
201 |
202 | ```
203 | private void initSwipeRefreshLayout() {
204 | mSwipeRefreshLayout.setColorSchemeResources(
205 | android.R.color.holo_blue_bright,
206 | android.R.color.holo_green_light,
207 | android.R.color.holo_orange_light);
208 |
209 | mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
210 | @Override
211 | public void onRefresh() {
212 | new Handler().postDelayed(new Runnable() {
213 | @Override
214 | public void run() {
215 | multipleItemQuickAdapter.notifyDataSetChanged();
216 | mSwipeRefreshLayout.setRefreshing(false);
217 | YUtils.showToast("刷新完成");
218 | }
219 | }, 2000);
220 | }
221 | });
222 | }
223 | ```
224 |
225 |
226 | #### 初始化RecyclerView
227 |
228 | ```
229 | private void initRecyclerView() {
230 | GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(), 5);
231 | mRecyclerView.setLayoutManager(gridLayoutManager);
232 |
233 | multipleItemQuickAdapter = new MultipleItemQuickAdapter(itemDataList);
234 |
235 | View headerView = getHeaderView(new View.OnClickListener() {
236 | @Override
237 | public void onClick(View view) {
238 | switch (view.getId()) {
239 | case R.id.my_header_image:
240 | YUtils.showToast("你点击了头像");
241 | break;
242 | case R.id.my_header_settings:
243 | YUtils.showToast("你点击了设置");
244 | break;
245 | }
246 | }
247 | });
248 |
249 | multipleItemQuickAdapter.addHeaderView(headerView);
250 |
251 | mRecyclerView.setAdapter(multipleItemQuickAdapter);
252 | }
253 | ```
254 |
255 |
256 | #### 添加Header
257 |
258 | ```
259 | private View getHeaderView(View.OnClickListener listener) {
260 | View headerView = getLayoutInflater().inflate(R.layout.layout_my_header, (ViewGroup) mRecyclerView.getParent(), false);
261 |
262 | CircleImageView myHeaderImage = headerView.findViewById(R.id.my_header_image);
263 | myHeaderImage.setImageResource(R.drawable.header_image);
264 | myHeaderImage.setOnClickListener(listener);
265 |
266 | TextView myHeaderName = headerView.findViewById(R.id.my_header_name);
267 | myHeaderName.setText("名字");
268 |
269 | TextView myHeaderMobile = headerView.findViewById(R.id.my_header_mobile);
270 | myHeaderMobile.setText("手机号");
271 |
272 | ImageView myHeaderSettings = headerView.findViewById(R.id.my_header_settings);
273 | myHeaderSettings.setOnClickListener(listener);
274 |
275 | return headerView;
276 | }
277 | ```
278 |
279 |
280 | #### 初始化Listener
281 |
282 | ```
283 | private void initListener() {
284 | multipleItemQuickAdapter.setSpanSizeLookup(new BaseQuickAdapter.SpanSizeLookup() {
285 | @Override
286 | public int getSpanSize(GridLayoutManager gridLayoutManager, int position) {
287 | return itemDataList.get(position).getSpanSize();
288 | }
289 | });
290 |
291 | multipleItemQuickAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
292 | @Override
293 | public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
294 |
295 | YUtils.showToast("第 " + position);
296 |
297 | //可以再加一层 类型 的判断,一般来说订单不是点了就消失的
298 | if (itemDataList.get(position).getItemType() == MultipleItem.TYPE_TOOLS) {
299 | if (itemDataList.get(position).isShow) {
300 | itemDataList.get(position).isShow = false;
301 | LogUtil.i("count = " + itemDataList.get(position).count);
302 | multipleItemQuickAdapter.notifyItemChanged(position + 1);
303 | } else
304 | itemDataList.get(position).isShow = false;
305 | }
306 |
307 | }
308 | });
309 |
310 | multipleItemQuickAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
311 | @Override
312 | public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
313 | switch (view.getId()) {
314 | case R.id.my_favorites:
315 | YUtils.showToast("收藏");
316 | break;
317 | case R.id.my_bands:
318 | YUtils.showToast("关注");
319 | break;
320 | case R.id.ll_my_order:
321 | YUtils.showToast("全部订单");
322 | break;
323 | case R.id.my_balance_btn:
324 | YUtils.showToast("立即充值");
325 | break;
326 | }
327 | }
328 | });
329 |
330 | }
331 | ```
332 |
333 | > 如果考虑到在GridLayoutManager复用item问题可以配置setSpanSizeLookup
334 | >
335 | > setOnItemClickListener,item点击事件
336 | >
337 | > setOnItemChildClickListener,item里面的子view点击事件
338 | >
339 | > item点击的时候,角标(徽章)消失,然后局部刷新
340 |
341 |
342 |
343 | ### 4.Bean
344 |
345 | > 实体类必须实现MultiItemEntity,在设置数据的时候,需要给每一个数据设置itemType
346 |
347 | ```
348 | public class MultipleItem implements MultiItemEntity {
349 |
350 | public static final int TYPE_COUNT = 1;
351 | public static final int TYPE_ORDER_HEADER = 2;
352 | public static final int TYPE_ORDER = 3;
353 | public static final int TYPE_BALANCE = 4;
354 | public static final int TYPE_TOOLS_HEADER = 5;
355 | public static final int TYPE_TOOLS = 6;
356 | private int itemType;
357 | private int spanSize;
358 |
359 | public MultipleItem(int itemType, int spanSize) {
360 | this.itemType = itemType;
361 | this.spanSize = spanSize;
362 | }
363 |
364 | @Override
365 | public int getItemType() {
366 | return itemType;
367 | }
368 |
369 | public int getSpanSize() {
370 | return spanSize;
371 | }
372 |
373 | public void setSpanSize(int spanSize) {
374 | this.spanSize = spanSize;
375 | }
376 |
377 |
378 | public String mString1;
379 |
380 | public String mString2;
381 |
382 | public boolean isShow;
383 |
384 | public int count;
385 |
386 | }
387 | ```
388 |
389 |
390 | ### 5.Adapter
391 |
392 | > 多布局关键写法就在Adapter里面,根据类型返回不同的layout,然后填充数据、处理事件等等。
393 | >
394 | > 在构造里面addItemType绑定type和layout的关系
395 |
396 | ```
397 | public class MultipleItemQuickAdapter extends BaseMultiItemQuickAdapter {
398 |
399 | public MultipleItemQuickAdapter(List data) {
400 | super(data);
401 | addItemType(MultipleItem.TYPE_COUNT, R.layout.layout_my_count);
402 | addItemType(MultipleItem.TYPE_ORDER_HEADER, R.layout.layout_my_order_header);
403 | addItemType(MultipleItem.TYPE_ORDER, R.layout.layout_my_order);
404 | addItemType(MultipleItem.TYPE_BALANCE, R.layout.layout_my_balance);
405 | addItemType(MultipleItem.TYPE_TOOLS_HEADER, R.layout.layout_my_tools_header);
406 | addItemType(MultipleItem.TYPE_TOOLS, R.layout.layout_my_tools);
407 | }
408 |
409 | @Override
410 | protected void convert(BaseViewHolder helper, MultipleItem item) {
411 | switch (helper.getItemViewType()) {
412 | case MultipleItem.TYPE_COUNT:
413 | helper.setText(R.id.my_favorites, item.mString1).addOnClickListener(R.id.my_favorites);
414 | helper.setText(R.id.my_bands, item.mString2).addOnClickListener(R.id.my_bands);
415 | break;
416 | case MultipleItem.TYPE_ORDER_HEADER:
417 | helper.addOnClickListener(R.id.ll_my_order);
418 | break;
419 | case MultipleItem.TYPE_ORDER:
420 | helper.setImageDrawable(R.id.my_order_image, ContextCompat.getDrawable(mContext, R.drawable.ic_launcher));
421 | helper.setText(R.id.my_order_name, item.mString1);
422 | if (item.isShow) {
423 | helper.getView(R.id.my_order_count).setVisibility(View.VISIBLE);
424 | if (item.count > 0) {
425 | if (item.count < 99) {
426 | helper.setText(R.id.my_order_count, String.valueOf(item.count));
427 | } else {
428 | helper.setText(R.id.my_order_count, String.valueOf("99+"));
429 | }
430 | } else {
431 | helper.getView(R.id.my_order_count).setVisibility(View.GONE);
432 | }
433 | } else {
434 | helper.getView(R.id.my_order_count).setVisibility(View.GONE);
435 | }
436 | break;
437 | case MultipleItem.TYPE_BALANCE:
438 | helper.setText(R.id.my_balance_text, item.mString1);
439 | helper.addOnClickListener(R.id.my_balance_btn);
440 | break;
441 | case MultipleItem.TYPE_TOOLS_HEADER:
442 | //helper.setText(R.id.tv_item_name, item.mString1);
443 | break;
444 | case MultipleItem.TYPE_TOOLS:
445 | helper.setImageDrawable(R.id.my_tools_image, ContextCompat.getDrawable(mContext, R.drawable.ic_launcher));
446 | helper.setText(R.id.my_tools_text, item.mString1);
447 | if (item.isShow) {
448 | helper.getView(R.id.my_tools_count).setVisibility(View.VISIBLE);
449 | if (item.count > 0) {
450 | if (item.count < 99) {
451 | helper.setText(R.id.my_tools_count, String.valueOf(item.count));
452 | } else {
453 | helper.setText(R.id.my_tools_count, String.valueOf("99+"));
454 | }
455 | } else {
456 | helper.getView(R.id.my_tools_count).setVisibility(View.GONE);
457 | }
458 | } else {
459 | helper.getView(R.id.my_tools_count).setVisibility(View.GONE);
460 | }
461 | break;
462 | }
463 | }
464 | ```
465 |
466 |
467 |
468 | > item的layout就不用贴了吧,就一般的布局。。
469 | >
470 | > 角标(徽章)的话没用BadgeView,只直接用ImageView写的。
471 | >
472 | > Demo是从项目里抽出来的,好像也没什么要注意的了吧。。忘了。。
473 |
474 |
475 |
476 | #### 博客:http://blog.csdn.net/yechaoa/article/details/78825588
477 |
478 |
479 |
480 | ```
481 | Copyright 2017 yechaoa
482 |
483 | Licensed under the Apache License, Version 2.0 (the "License");
484 | you may not use this file except in compliance with the License.
485 | You may obtain a copy of the License at
486 |
487 | http://www.apache.org/licenses/LICENSE-2.0
488 |
489 | Unless required by applicable law or agreed to in writing, software
490 | distributed under the License is distributed on an "AS IS" BASIS,
491 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
492 | See the License for the specific language governing permissions and
493 | limitations under the License.
494 |
495 | ```
496 |
--------------------------------------------------------------------------------