├── .gitignore ├── .idea ├── codeStyles │ └── Project.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── Behavior实现伸缩标题栏.gif ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── android │ │ └── of │ │ └── road │ │ └── com │ │ └── coordinatorlayout │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── android │ │ │ └── of │ │ │ └── road │ │ │ └── com │ │ │ ├── behavior │ │ │ ├── AlipayBehavior.java │ │ │ ├── AlphaHeaderLayoutBehavior.java │ │ │ ├── TransferHeaderBehavior.java │ │ │ ├── TranslucentBehavior.java │ │ │ ├── fragment │ │ │ │ └── UserInfoFragment.java │ │ │ ├── user │ │ │ │ ├── UserActionBehavior.java │ │ │ │ ├── UserCardViewBehavior.java │ │ │ │ ├── UserHeaderBehavior.java │ │ │ │ ├── UserNameBehavior.java │ │ │ │ ├── UserStartBehavior.java │ │ │ │ ├── UserTabLayoutBehavior.java │ │ │ │ └── UserTranslucentBehavior.java │ │ │ └── utils │ │ │ │ └── DensityUtils.java │ │ │ ├── coordinatorlayout │ │ │ ├── AlipayBehaviorActivity.java │ │ │ ├── BehaviorOverlapTopActivity.java │ │ │ ├── MainActivity.java │ │ │ ├── TransferHeaderActivity.java │ │ │ ├── TranslucentBehaviorActivity.java │ │ │ └── UserInfoActivity.java │ │ │ ├── course1 │ │ │ ├── Course1MainActivity.java │ │ │ ├── CreateAppBarLayoutActivity.java │ │ │ └── CreateCoordinatorLayoutActivity.java │ │ │ └── investment │ │ │ ├── InvestmentMainActivity.java │ │ │ ├── behavior │ │ │ └── MerchantInfoBehavior.java │ │ │ ├── fragment │ │ │ ├── MyShopItemRecyclerViewAdapter.java │ │ │ ├── ShopItemFragment.java │ │ │ └── dummy │ │ │ │ └── DummyContent.java │ │ │ └── utls │ │ │ └── StatusBarUtil.java │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ ├── background_user_left_action.xml │ │ ├── background_user_right_action.xml │ │ ├── background_user_star.xml │ │ ├── ic_arrow_back_black_24dp.xml │ │ ├── ic_arrow_back_white_24dp.xml │ │ ├── ic_call_24dp.xml │ │ ├── ic_launcher_background.xml │ │ ├── ic_message_24dp.xml │ │ └── ic_star_white_24dp.xml │ │ ├── layout │ │ ├── activity_apay_behavior.xml │ │ ├── activity_behavior_overlap_top.xml │ │ ├── activity_course1_main.xml │ │ ├── activity_create_app_bar_layout.xml │ │ ├── activity_create_coordinator_layout.xml │ │ ├── activity_investment_main.xml │ │ ├── activity_main.xml │ │ ├── activity_transfer_header.xml │ │ ├── activity_translucent_behavior.xml │ │ ├── activity_user_info.xml │ │ ├── content_investment_main.xml │ │ ├── content_main.xml │ │ ├── fragment_shopitem.xml │ │ ├── fragment_shopitem_list.xml │ │ ├── fragment_user_info.xml │ │ ├── layout_apay_content.xml │ │ ├── layout_behavior_overlap_top_content.xml │ │ ├── layout_scroll_content.xml │ │ ├── layout_tr_content.xml │ │ ├── layout_user_info_content.xml │ │ └── line_item_layout.xml │ │ ├── menu │ │ └── menu_main.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.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 │ │ ├── default_header.png │ │ ├── design.png │ │ ├── ic_launcher.png │ │ ├── ic_launcher_round.png │ │ ├── icon_card.png │ │ ├── icon_pay.png │ │ ├── icon_scanf.png │ │ └── icon_shoupay.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ ├── ic_launcher_round.png │ │ ├── icon_server_app_card.png │ │ ├── icon_server_app_door.png │ │ ├── icon_server_app_scanf.png │ │ └── icon_server_app_wallet.png │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── sb_ids.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── android │ └── of │ └── road │ └── com │ └── coordinatorlayout │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── userinfo.gif /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the ART/Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | out/ 15 | 16 | # Gradle files 17 | .gradle/ 18 | build/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log 28 | 29 | # Android Studio Navigation editor temp files 30 | .navigation/ 31 | 32 | # Android Studio captures folder 33 | captures/ 34 | 35 | # IntelliJ 36 | *.iml 37 | .idea/workspace.xml 38 | .idea/tasks.xml 39 | .idea/gradle.xml 40 | .idea/assetWizardSettings.xml 41 | .idea/dictionaries 42 | .idea/libraries 43 | .idea/caches 44 | 45 | # Keystore files 46 | # Uncomment the following line if you do not want to check your keystore files in. 47 | #*.jks 48 | 49 | # External native build folder generated in Android Studio 2.2 and later 50 | .externalNativeBuild 51 | 52 | # Google Services (e.g. APIs or Firebase) 53 | google-services.json 54 | 55 | # Freeline 56 | freeline.py 57 | freeline/ 58 | freeline_project_description.json 59 | 60 | # fastlane 61 | fastlane/report.xml 62 | fastlane/Preview.html 63 | fastlane/screenshots 64 | fastlane/test_output 65 | fastlane/readme.md 66 | -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 15 | 16 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 27 | 28 | 29 | 30 | 31 | 32 | 34 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Behavior实现伸缩标题栏.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aohanyao/CoordinatorLayout/52afe442e4fb6277e8b5c6ccb84f4fbd088cdfd6/Behavior实现伸缩标题栏.gif -------------------------------------------------------------------------------- /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 | # CoordinatorLayout 2 | CoordinatorLayout demo 3 | 4 | ![Behavior实现伸缩标题栏](Behavior实现伸缩标题栏.gif) 5 | 6 | ![UserInfo](userinfo.gif) 7 | 8 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 26 5 | defaultConfig { 6 | applicationId "android.of.road.com.coordinatorlayout" 7 | minSdkVersion 19 8 | targetSdkVersion 26 9 | versionCode 1 10 | versionName "1.0" 11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | implementation fileTree(dir: 'libs', include: ['*.jar']) 23 | implementation 'com.android.support:appcompat-v7:26.0.2' 24 | implementation 'com.android.support.constraint:constraint-layout:1.1.2' 25 | implementation 'com.android.support:design:26.0.2' 26 | implementation 'com.android.support:cardview-v7:26.0.2' 27 | implementation 'de.hdodenhof:circleimageview:1.3.0' 28 | 29 | implementation 'com.android.support:support-v4:26.0.2' 30 | implementation 'com.android.support:recyclerview-v7:26.0.2' 31 | testImplementation 'junit:junit:4.12' 32 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 33 | implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.35' 34 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 35 | 36 | } 37 | -------------------------------------------------------------------------------- /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/androidTest/java/android/of/road/com/coordinatorlayout/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package android.of.road.com.coordinatorlayout; 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() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("android.of.road.com.coordinatorlayout", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /app/src/main/java/android/of/road/com/behavior/AlipayBehavior.java: -------------------------------------------------------------------------------- 1 | package android.of.road.com.behavior; 2 | 3 | import android.content.Context; 4 | import android.of.road.com.behavior.utils.DensityUtils; 5 | import android.support.design.widget.CoordinatorLayout; 6 | import android.support.v7.widget.Toolbar; 7 | import android.util.AttributeSet; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | import android.widget.LinearLayout; 11 | 12 | /** 13 | * Created by jc on 2018-07-13. 14 | * Version:1.0 15 | * Description: 16 | * ChangeLog: 17 | */ 18 | public class AlipayBehavior extends CoordinatorLayout.Behavior { 19 | 20 | /** 21 | * 下标 22 | */ 23 | private int mPosition = -1; 24 | /** 25 | * X轴坐标 26 | */ 27 | private float mViewMaxX = 0; 28 | 29 | /** 30 | * View的宽度 31 | */ 32 | private int mViewWidth; 33 | /** 34 | * View的高度 35 | */ 36 | private int mViewHeight; 37 | 38 | /** 39 | * Y轴的最大高度 40 | */ 41 | private int mViewMaxY = 0; 42 | 43 | 44 | public AlipayBehavior(Context context, AttributeSet attrs) { 45 | super(context, attrs); 46 | } 47 | 48 | @Override 49 | public boolean layoutDependsOn(CoordinatorLayout parent, LinearLayout child, View dependency) { 50 | return dependency instanceof Toolbar; 51 | } 52 | 53 | @Override 54 | public boolean onDependentViewChanged(CoordinatorLayout parent, LinearLayout child, View dependency) { 55 | if (mPosition == -1) {//未初始化 56 | mPosition = Integer.parseInt((String) child.getTag()); 57 | //计算出每个View的宽度 58 | mViewWidth = dependency.getWidth() / 4/*四个View*/; 59 | //高度 60 | mViewHeight = child.getHeight(); 61 | //重新规划 宽度 62 | ViewGroup.LayoutParams layoutParams = child.getLayoutParams(); 63 | if (layoutParams != null) { 64 | layoutParams.width = mViewWidth; 65 | } 66 | child.setLayoutParams(layoutParams); 67 | 68 | // 总宽度 除以四。得出每一个子View的宽度,居中为 69 | //计算居中X轴 70 | mViewMaxX = mViewWidth * mPosition; 71 | //计算Y轴 72 | mViewMaxY = (int) (child.getY() + DensityUtils.dp2px(parent.getContext(), 50f)); 73 | } 74 | 75 | //计算百分比 当前的百分比其实是没有减去状态栏的 76 | float mPercent = dependency.getY() / (dependency.getHeight()/* - ScreenUtils.getStatusHeight(parent.getContext())*/); 77 | if (mPercent >= 1f) 78 | mPercent = 1; 79 | 80 | // 动态更改 View的高度 81 | ViewGroup.LayoutParams layoutParams = child.getLayoutParams(); 82 | if (layoutParams != null) { 83 | layoutParams.height = (int) (mViewHeight - (mViewHeight /** 0.8f*/) * mPercent); 84 | layoutParams.width = (int) (mViewWidth - (mViewWidth * mPercent)); 85 | child.setLayoutParams(layoutParams); 86 | } 87 | 88 | //更改 内部文字的透明底 89 | View mTextTitleView = child.getChildAt(1); 90 | if (mTextTitleView != null) { 91 | mTextTitleView.setAlpha(1 - (mPercent > 0.4 ? 1 : mPercent)); 92 | } 93 | 94 | // 更改内部imageView的大小 95 | View mImageTitleView = child.getChildAt(0); 96 | if (mImageTitleView != null) { 97 | mImageTitleView.setScaleX(1 - (0.4f * mPercent)); 98 | mImageTitleView.setScaleY(1 - (0.4f * mPercent)); 99 | } 100 | 101 | 102 | //设置X轴坐标//没有计算状态栏的情况之下,滑动并不是完整的 103 | child.setX(mViewMaxX - (mViewMaxX - 50/*左边的距离*/) * mPercent); 104 | 105 | 106 | // 设置Y轴坐标 107 | child.setY(mViewMaxY - (mViewMaxY * 1.4f) * mPercent); 108 | 109 | 110 | return true; 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /app/src/main/java/android/of/road/com/behavior/AlphaHeaderLayoutBehavior.java: -------------------------------------------------------------------------------- 1 | package android.of.road.com.behavior; 2 | 3 | import android.content.Context; 4 | import android.support.design.widget.CoordinatorLayout; 5 | import android.support.v7.widget.Toolbar; 6 | import android.util.AttributeSet; 7 | import android.view.View; 8 | 9 | 10 | /** 11 | * Created by jc on 2018-07-17. 12 | * Version:1.0 13 | * Description: 透明度变化的头布局 14 | * ChangeLog: 15 | */ 16 | public class AlphaHeaderLayoutBehavior extends CoordinatorLayout.Behavior { 17 | public AlphaHeaderLayoutBehavior(Context context, AttributeSet attrs) { 18 | super(context, attrs); 19 | } 20 | 21 | @Override 22 | public boolean layoutDependsOn(CoordinatorLayout parent, Toolbar child, View dependency) { 23 | return dependency instanceof Toolbar; 24 | } 25 | 26 | @Override 27 | public boolean onDependentViewChanged(CoordinatorLayout parent, Toolbar child, View dependency) { 28 | float percent = dependency.getY() / dependency.getHeight(); 29 | if (percent >= 0.8f) 30 | percent = 1; 31 | 32 | child.setAlpha(percent); 33 | return true; 34 | } 35 | } 36 | 37 | -------------------------------------------------------------------------------- /app/src/main/java/android/of/road/com/behavior/TransferHeaderBehavior.java: -------------------------------------------------------------------------------- 1 | package android.of.road.com.behavior; 2 | 3 | import android.content.Context; 4 | import android.support.design.widget.CoordinatorLayout; 5 | import android.support.v7.widget.Toolbar; 6 | import android.util.AttributeSet; 7 | import android.view.View; 8 | import android.widget.ImageView; 9 | 10 | /** 11 | * Created by jc on 2018-07-12. 12 | * Version:1.0 13 | * Description: 14 | * ChangeLog: 15 | */ 16 | public class TransferHeaderBehavior extends CoordinatorLayout.Behavior { 17 | 18 | /** 19 | * 处于中心时候原始X轴 20 | */ 21 | private int mOriginalHeaderX = 0; 22 | /** 23 | * 处于中心时候原始Y轴 24 | */ 25 | private int mOriginalHeaderY = 0; 26 | 27 | 28 | public TransferHeaderBehavior(Context context, AttributeSet attrs) { 29 | super(context, attrs); 30 | } 31 | 32 | @Override 33 | public boolean layoutDependsOn(CoordinatorLayout parent, ImageView child, View dependency) { 34 | return dependency instanceof Toolbar; 35 | } 36 | 37 | @Override 38 | public boolean onDependentViewChanged(CoordinatorLayout parent, ImageView child, View dependency) { 39 | // 计算X轴坐标 40 | if (mOriginalHeaderX == 0) { 41 | this.mOriginalHeaderX = dependency.getWidth() / 2 - child.getWidth() / 2; 42 | } 43 | // 计算Y轴坐标 44 | if (mOriginalHeaderY == 0) { 45 | mOriginalHeaderY = dependency.getHeight() - child.getHeight(); 46 | } 47 | //X轴百分比 48 | float mPercentX = dependency.getY() / mOriginalHeaderX; 49 | if (mPercentX >= 1) { 50 | mPercentX = 1; 51 | } 52 | //Y轴百分比 53 | float mPercentY = dependency.getY() / mOriginalHeaderY; 54 | if (mPercentY >= 1) { 55 | mPercentY = 1; 56 | } 57 | 58 | float x = mOriginalHeaderX - mOriginalHeaderX * mPercentX; 59 | if (x <= child.getWidth()) { 60 | x = child.getWidth(); 61 | } 62 | // TODO 头像的放大和缩小没做 63 | 64 | child.setX(x); 65 | child.setY(mOriginalHeaderY - mOriginalHeaderY * mPercentY); 66 | return true; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /app/src/main/java/android/of/road/com/behavior/TranslucentBehavior.java: -------------------------------------------------------------------------------- 1 | package android.of.road.com.behavior; 2 | 3 | import android.content.Context; 4 | import android.graphics.Color; 5 | import android.support.design.widget.CoordinatorLayout; 6 | import android.support.v7.widget.Toolbar; 7 | import android.util.AttributeSet; 8 | import android.view.View; 9 | import android.widget.TextView; 10 | 11 | /** 12 | * Created by jc on 2018-07-12. 13 | * Version:1.0 14 | * Description: 15 | * ChangeLog: 16 | */ 17 | public class TranslucentBehavior extends CoordinatorLayout.Behavior { 18 | 19 | /**标题栏的高度*/ 20 | private int mToolbarHeight = 0; 21 | 22 | public TranslucentBehavior(Context context, AttributeSet attrs) { 23 | super(context, attrs); 24 | } 25 | 26 | @Override 27 | public boolean layoutDependsOn(CoordinatorLayout parent, Toolbar child, View dependency) { 28 | return dependency instanceof TextView; 29 | } 30 | 31 | /** 32 | * 必须要加上 layout_anchor,对方也要layout_collapseMode才能使用 33 | */ 34 | 35 | @Override 36 | public boolean onDependentViewChanged(CoordinatorLayout parent, Toolbar child, View dependency) { 37 | 38 | // 初始化高度 39 | if (mToolbarHeight == 0) { 40 | mToolbarHeight = child.getBottom() * 2;//为了更慢的 41 | } 42 | // 43 | //计算toolbar从开始移动到最后的百分比 44 | float percent = dependency.getY() / mToolbarHeight; 45 | 46 | //百分大于1,直接赋值为1 47 | if (percent >= 1) { 48 | percent = 1f; 49 | } 50 | 51 | // 计算alpha通道值 52 | float alpha = percent * 255; 53 | 54 | 55 | //设置背景颜色 56 | child.setBackgroundColor(Color.argb((int) alpha, 63, 81, 181)); 57 | 58 | return true; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /app/src/main/java/android/of/road/com/behavior/fragment/UserInfoFragment.java: -------------------------------------------------------------------------------- 1 | package android.of.road.com.behavior.fragment; 2 | 3 | 4 | import android.os.Bundle; 5 | import android.support.v4.app.Fragment; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | 10 | import android.of.road.com.coordinatorlayout.R; 11 | 12 | /** 13 | * A simple {@link Fragment} subclass. 14 | */ 15 | public class UserInfoFragment extends Fragment { 16 | 17 | 18 | public UserInfoFragment() { 19 | // Required empty public constructor 20 | } 21 | 22 | 23 | @Override 24 | public View onCreateView(LayoutInflater inflater, ViewGroup container, 25 | Bundle savedInstanceState) { 26 | // Inflate the layout for this fragment 27 | return inflater.inflate(R.layout.fragment_user_info, container, false); 28 | } 29 | 30 | public static UserInfoFragment newInstance() { 31 | 32 | Bundle args = new Bundle(); 33 | 34 | UserInfoFragment fragment = new UserInfoFragment(); 35 | fragment.setArguments(args); 36 | return fragment; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /app/src/main/java/android/of/road/com/behavior/user/UserActionBehavior.java: -------------------------------------------------------------------------------- 1 | package android.of.road.com.behavior.user; 2 | 3 | import android.content.Context; 4 | import android.of.road.com.behavior.utils.DensityUtils; 5 | import android.support.design.widget.CoordinatorLayout; 6 | import android.util.AttributeSet; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.LinearLayout; 10 | 11 | public class UserActionBehavior extends CoordinatorLayout.Behavior { 12 | private float mViewWidth = 0; 13 | private float mDiffWidth = 0; 14 | private float mViewHeight = 0; 15 | 16 | 17 | public UserActionBehavior(Context context, AttributeSet attrs) { 18 | super(context, attrs); 19 | } 20 | 21 | @Override 22 | public boolean layoutDependsOn(CoordinatorLayout parent, LinearLayout child, View dependency) { 23 | return dependency instanceof LinearLayout; 24 | } 25 | 26 | @Override 27 | public boolean onDependentViewChanged(CoordinatorLayout parent, LinearLayout child, View dependency) { 28 | 29 | if (mViewWidth == 0) { 30 | mViewWidth = (float) (dependency.getWidth() * 0.903); 31 | dependency.getWidth(); 32 | } 33 | 34 | 35 | ViewGroup.LayoutParams layoutParams = child.getLayoutParams(); 36 | if (layoutParams != null) { 37 | //宽度 跟随滑动进行减少 38 | layoutParams.width = (int) mViewWidth; 39 | //X轴 跟随滑动进行加大 40 | child.setX(dependency.getWidth() * 0.048f); 41 | child.setLayoutParams(layoutParams); 42 | } 43 | 44 | //计算百分比 45 | float percent = dependency.getY() / (child.getHeight() * 2); 46 | if (percent >= 1) { 47 | percent = 1f; 48 | } 49 | 50 | 51 | float alpha = percent /** 1.2f*/; 52 | if (alpha > 1) { 53 | alpha = 1; 54 | // child.setVisibility(View.GONE); 55 | } 56 | 57 | 58 | //设置透明度 59 | child.setAlpha(1 - alpha); 60 | if (child.getAlpha() <= 0.4) { 61 | // child.setVisibility(View.GONE); 62 | } 63 | if (child.getAlpha() > 0.4) { 64 | // child.setVisibility(View.VISIBLE); 65 | } 66 | 67 | 68 | int mCardViewHeight = DensityUtils.dp2px(parent.getContext(), 235); 69 | float mCardPercent = dependency.getY() / dependency.getHeight(); 70 | if (mCardPercent >= 1) { 71 | mCardPercent = 1; 72 | } 73 | child.setY(mCardViewHeight - mCardViewHeight * mCardPercent); 74 | return true; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /app/src/main/java/android/of/road/com/behavior/user/UserCardViewBehavior.java: -------------------------------------------------------------------------------- 1 | package android.of.road.com.behavior.user; 2 | 3 | import android.content.Context; 4 | import android.of.road.com.behavior.utils.DensityUtils; 5 | import android.support.design.widget.CoordinatorLayout; 6 | import android.support.v7.widget.CardView; 7 | import android.util.AttributeSet; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | 11 | public class UserCardViewBehavior extends CoordinatorLayout.Behavior { 12 | 13 | private int mMaxY = 0; 14 | private int mMargin = 0; 15 | private int mViewHeight = 0; 16 | private float mViewWidth = 0; 17 | private float mDiffWith = 0; 18 | 19 | public UserCardViewBehavior(Context context, AttributeSet attrs) { 20 | super(context, attrs); 21 | } 22 | 23 | @Override 24 | public boolean layoutDependsOn(CoordinatorLayout parent, CardView child, View dependency) { 25 | return dependency instanceof CardView; 26 | } 27 | 28 | @Override 29 | public boolean onDependentViewChanged(CoordinatorLayout parent, CardView child, View dependency) { 30 | if (mMaxY == 0) { 31 | mMaxY = DensityUtils.dp2px(parent.getContext(), 85); 32 | mMargin = DensityUtils.dp2px(parent.getContext(), 20); 33 | mViewHeight = child.getHeight(); 34 | mViewWidth = (int) (child.getWidth() * 0.9f); 35 | mDiffWith = (int) (child.getWidth() * 0.1f); 36 | } 37 | 38 | 39 | //计算百分比 40 | float percent = dependency.getY() / dependency.getHeight(); 41 | if (percent >= 1) { 42 | percent = 1f; 43 | } 44 | if (percent <= 0) { 45 | percent = 0f; 46 | } 47 | 48 | child.setY(mMaxY - percent * mMaxY); 49 | 50 | //更改高度和左右间距 51 | 52 | ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) child.getLayoutParams(); 53 | 54 | if (layoutParams != null) { 55 | // 使用间距的时候会有点问题,更改为 修改宽度和X轴 56 | // 如果他是1 57 | float mOffsetWidth = mDiffWith * percent; 58 | layoutParams.width = (int) (mViewWidth + mOffsetWidth); 59 | try { 60 | child.setX((mDiffWith / 2) - mOffsetWidth / 2); 61 | } catch (Exception e) { 62 | e.printStackTrace(); 63 | } 64 | 65 | // 66 | // // 更改 67 | layoutParams.height = (int) (mViewHeight - mViewHeight * percent); 68 | } 69 | 70 | //获取的子view 71 | View childView = child.getChildAt(0); 72 | 73 | // 透明度渐变不是那么理想 74 | float alpha = percent * 2; 75 | if (alpha > 0.5) { 76 | alpha = 1; 77 | } 78 | childView.setAlpha(1 - alpha); 79 | 80 | return true; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /app/src/main/java/android/of/road/com/behavior/user/UserHeaderBehavior.java: -------------------------------------------------------------------------------- 1 | package android.of.road.com.behavior.user; 2 | 3 | import android.content.Context; 4 | import android.support.design.widget.CoordinatorLayout; 5 | import android.util.AttributeSet; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.widget.ImageView; 9 | 10 | /** 11 | * 用户头像的Behavior 12 | */ 13 | public class UserHeaderBehavior extends CoordinatorLayout.Behavior { 14 | 15 | private int mMaxX = 0; 16 | private int mDiffX = 0; 17 | private int mDiffSize = 0; 18 | private int mMaxY = 0; 19 | private int mDiffY = 0; 20 | 21 | 22 | private int mHeaderSize = 0; 23 | 24 | public UserHeaderBehavior(Context context, AttributeSet attrs) { 25 | super(context, attrs); 26 | } 27 | 28 | @Override 29 | public boolean layoutDependsOn(CoordinatorLayout parent, ImageView child, View dependency) { 30 | return dependency instanceof ImageView; 31 | } 32 | 33 | @Override 34 | public boolean onDependentViewChanged(CoordinatorLayout parent, ImageView child, View dependency) { 35 | //初始化 目标最大的坐标轴 36 | if (mMaxX == 0 || mMaxY == 0) { 37 | mMaxX = dependency.getWidth() / 2 - child.getWidth() / 2; 38 | //X轴的差距 39 | mDiffX = mMaxX - 100/*暂时定死*/; 40 | //宽高的差距是 41 | mDiffSize = (int) (child.getWidth() * 0.4); 42 | 43 | // 暂时 赋值为一个自己的高度 44 | mMaxY = child.getHeight(); 45 | mDiffY = (int) (child.getHeight()); 46 | 47 | mHeaderSize = child.getWidth(); 48 | 49 | } 50 | 51 | 52 | //计算百分比 53 | float percent = dependency.getY() / dependency.getHeight(); 54 | if (percent >= 1) { 55 | percent = 1f; 56 | } 57 | 58 | 59 | //设置X轴坐标 60 | child.setX(mMaxX - mDiffX * percent); 61 | child.setY(mMaxY - mDiffY * percent); 62 | 63 | 64 | //宽高 65 | ViewGroup.LayoutParams layoutParams = child.getLayoutParams(); 66 | if (layoutParams != null) { 67 | layoutParams.width = (int) (mHeaderSize - mDiffSize * percent); 68 | layoutParams.height = (int) (mHeaderSize - mDiffSize * percent); 69 | 70 | child.setLayoutParams(layoutParams); 71 | } 72 | 73 | 74 | return true; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /app/src/main/java/android/of/road/com/behavior/user/UserNameBehavior.java: -------------------------------------------------------------------------------- 1 | package android.of.road.com.behavior.user; 2 | 3 | import android.content.Context; 4 | import android.of.road.com.behavior.utils.DensityUtils; 5 | import android.support.design.widget.CoordinatorLayout; 6 | import android.util.AttributeSet; 7 | import android.view.View; 8 | import android.widget.TextView; 9 | 10 | public class UserNameBehavior extends CoordinatorLayout.Behavior { 11 | 12 | private int mMaxX = 0; 13 | private int mMaxY = 0; 14 | 15 | private int mDiffY = 0; 16 | private int mDiffX = 0; 17 | 18 | public UserNameBehavior(Context context, AttributeSet attrs) { 19 | super(context, attrs); 20 | } 21 | 22 | @Override 23 | public boolean layoutDependsOn(CoordinatorLayout parent, TextView child, View dependency) { 24 | return dependency instanceof TextView; 25 | } 26 | 27 | @Override 28 | public boolean onDependentViewChanged(CoordinatorLayout parent, TextView child, View dependency) { 29 | if (mMaxX == 0 || mMaxY == 0) { 30 | //X轴 31 | mMaxX = dependency.getWidth() / 2 - child.getWidth() / 2; 32 | //Y轴 33 | mMaxY = DensityUtils.dp2px(parent.getContext(), 125f); 34 | 35 | //缩小的时候的Y轴 36 | mDiffY = mMaxY - DensityUtils.dp2px(parent.getContext(), -8f); 37 | // 缩小的时候的X轴 38 | mDiffX = mMaxX - DensityUtils.dp2px(parent.getContext(), 90f); 39 | } 40 | 41 | 42 | //计算百分比 43 | float percent = dependency.getY() / dependency.getHeight(); 44 | if (percent >= 1) { 45 | percent = 1f; 46 | } 47 | 48 | 49 | child.setX(mMaxX - mDiffX * percent); 50 | child.setY(mMaxY - mDiffY * percent); 51 | 52 | return true; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /app/src/main/java/android/of/road/com/behavior/user/UserStartBehavior.java: -------------------------------------------------------------------------------- 1 | package android.of.road.com.behavior.user; 2 | 3 | import android.content.Context; 4 | import android.of.road.com.behavior.utils.DensityUtils; 5 | import android.support.design.widget.CoordinatorLayout; 6 | import android.util.AttributeSet; 7 | import android.view.View; 8 | import android.widget.RelativeLayout; 9 | 10 | public class UserStartBehavior extends CoordinatorLayout.Behavior { 11 | 12 | private int mMaxX = 0; 13 | private int mMaxY = 0; 14 | 15 | private int mDiffY = 0; 16 | private int mDiffX = 0; 17 | 18 | public UserStartBehavior(Context context, AttributeSet attrs) { 19 | super(context, attrs); 20 | } 21 | 22 | @Override 23 | public boolean layoutDependsOn(CoordinatorLayout parent, RelativeLayout child, View dependency) { 24 | return dependency instanceof RelativeLayout; 25 | } 26 | 27 | @Override 28 | public boolean onDependentViewChanged(CoordinatorLayout parent, RelativeLayout child, View dependency) { 29 | if (mMaxX == 0 || mMaxY == 0) { 30 | //X轴 31 | mMaxX = dependency.getWidth() / 2 - child.getWidth() / 2; 32 | //Y轴 33 | mMaxY = DensityUtils.dp2px(parent.getContext(), 105f); 34 | 35 | //缩小的时候的Y轴 36 | mDiffY = mMaxY - DensityUtils.dp2px(parent.getContext(), 22f); 37 | // 缩小的时候的X轴 38 | mDiffX = mMaxX - DensityUtils.dp2px(parent.getContext(), 90f); 39 | } 40 | 41 | 42 | //计算百分比 43 | float percent = dependency.getY() / dependency.getHeight(); 44 | if (percent >= 1) { 45 | percent = 1f; 46 | } 47 | 48 | 49 | child.setX(mMaxX - mDiffX * percent); 50 | child.setY(mMaxY - mDiffY * percent); 51 | 52 | return true; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /app/src/main/java/android/of/road/com/behavior/user/UserTabLayoutBehavior.java: -------------------------------------------------------------------------------- 1 | package android.of.road.com.behavior.user; 2 | 3 | import android.content.Context; 4 | import android.support.design.widget.CoordinatorLayout; 5 | import android.support.design.widget.TabLayout; 6 | import android.util.AttributeSet; 7 | import android.view.View; 8 | 9 | public class UserTabLayoutBehavior extends CoordinatorLayout.Behavior { 10 | 11 | 12 | private int mMaxY = 0; 13 | 14 | private int mDiffY = 0; 15 | 16 | 17 | public UserTabLayoutBehavior(Context context, AttributeSet attrs) { 18 | super(context, attrs); 19 | } 20 | 21 | @Override 22 | public boolean layoutDependsOn(CoordinatorLayout parent, TabLayout child, View dependency) { 23 | return dependency instanceof TabLayout; 24 | } 25 | 26 | @Override 27 | public boolean onDependentViewChanged(CoordinatorLayout parent, TabLayout child, View dependency) { 28 | //计算百分比 29 | float percent = dependency.getY() / dependency.getHeight(); 30 | if (percent >= 1) { 31 | percent = 1f; 32 | } 33 | 34 | if (mMaxY == 0) { 35 | mMaxY = dependency.getBottom() - child.getHeight(); 36 | mDiffY = (int) (mMaxY - child.getHeight() * 0.4f); 37 | } 38 | //todo 遗留tablayout悬停的问题 39 | 40 | child.setY(mMaxY - mDiffY * percent); 41 | 42 | return true; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /app/src/main/java/android/of/road/com/behavior/user/UserTranslucentBehavior.java: -------------------------------------------------------------------------------- 1 | package android.of.road.com.behavior.user; 2 | 3 | import android.content.Context; 4 | import android.graphics.Color; 5 | import android.of.road.com.coordinatorlayout.R; 6 | import android.support.design.widget.CoordinatorLayout; 7 | import android.support.v7.widget.Toolbar; 8 | import android.util.AttributeSet; 9 | import android.util.Log; 10 | import android.view.View; 11 | 12 | /** 13 | * Created by jc on 2018-07-12. 14 | * Version:1.0 15 | * Description: 16 | * ChangeLog: 17 | */ 18 | public class UserTranslucentBehavior extends CoordinatorLayout.Behavior { 19 | 20 | private int mToolbarHeight = 0; 21 | 22 | public UserTranslucentBehavior(Context context, AttributeSet attrs) { 23 | super(context, attrs); 24 | } 25 | 26 | @Override 27 | public boolean layoutDependsOn(CoordinatorLayout parent, Toolbar child, View dependency) { 28 | return super.layoutDependsOn(parent, child, dependency); 29 | } 30 | 31 | /** 32 | * 必须要加上 layout_anchor,对方也要layout_collapseMode才能使用 33 | */ 34 | 35 | @Override 36 | public boolean onDependentViewChanged(CoordinatorLayout parent, Toolbar child, View dependency) { 37 | 38 | // 初始化高度 39 | if (mToolbarHeight == 0) { 40 | mToolbarHeight = child.getBottom() * 2;//为了更慢的 41 | } 42 | // 43 | //计算toolbar从开始移动到最后的百分比 44 | float percent = dependency.getY() / mToolbarHeight; 45 | 46 | //百分大于1,直接赋值为1 47 | if (percent >= 1) { 48 | percent = 1f; 49 | } 50 | if (percent > 0.4) { 51 | child.setNavigationIcon(R.drawable.ic_arrow_back_black_24dp); 52 | } else { 53 | child.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp); 54 | } 55 | 56 | 57 | // 到底顶部了,再计算透明度 58 | if (percent < 0.9) { 59 | percent = 0; 60 | } 61 | // 计算alpha通道值 62 | float alpha = percent * 255; 63 | // 255 不透明 0 透明 64 | // 展开的时候的比例是0 65 | Log.e("onDependentViewChanged", "percent:" + percent + " alpha:" + alpha); 66 | 67 | 68 | //设置背景颜色 69 | child.setBackgroundColor(Color.argb((int) alpha, 255, 255, 255)); 70 | 71 | return true; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /app/src/main/java/android/of/road/com/behavior/utils/DensityUtils.java: -------------------------------------------------------------------------------- 1 | package android.of.road.com.behavior.utils; 2 | 3 | import android.content.Context; 4 | import android.util.TypedValue; 5 | 6 | //常用单位转换的辅助类 7 | public class DensityUtils { 8 | private DensityUtils() { 9 | /* cannot be instantiated */ 10 | throw new UnsupportedOperationException("不能被实例化"); 11 | } 12 | 13 | /** 14 | * dp转px 15 | * 16 | * @param context 17 | * @param dpVal 18 | * @return 19 | */ 20 | public static int dp2px(Context context, float dpVal) { 21 | return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 22 | dpVal, context.getResources().getDisplayMetrics()); 23 | } 24 | 25 | /** 26 | * sp转px 27 | * 28 | * @param context 29 | * @param spVal 30 | * @return 31 | */ 32 | public static int sp2px(Context context, float spVal) { 33 | return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 34 | spVal, context.getResources().getDisplayMetrics()); 35 | } 36 | 37 | /** 38 | * px转dp 39 | * 40 | * @param context 41 | * @param pxVal 42 | * @return 43 | */ 44 | public static float px2dp(Context context, float pxVal) { 45 | final float scale = context.getResources().getDisplayMetrics().density; 46 | return (pxVal / scale); 47 | } 48 | 49 | /** 50 | * px转sp 51 | * 52 | * @param context 53 | * @param pxVal 54 | * @return 55 | */ 56 | public static float px2sp(Context context, float pxVal) { 57 | return (pxVal / context.getResources().getDisplayMetrics().scaledDensity); 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /app/src/main/java/android/of/road/com/coordinatorlayout/AlipayBehaviorActivity.java: -------------------------------------------------------------------------------- 1 | package android.of.road.com.coordinatorlayout; 2 | 3 | import android.support.v7.app.AppCompatActivity; 4 | import android.os.Bundle; 5 | 6 | public class AlipayBehaviorActivity extends AppCompatActivity { 7 | 8 | @Override 9 | protected void onCreate(Bundle savedInstanceState) { 10 | super.onCreate(savedInstanceState); 11 | setContentView(R.layout.activity_apay_behavior); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /app/src/main/java/android/of/road/com/coordinatorlayout/BehaviorOverlapTopActivity.java: -------------------------------------------------------------------------------- 1 | package android.of.road.com.coordinatorlayout; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | 6 | public class BehaviorOverlapTopActivity extends AppCompatActivity { 7 | 8 | @Override 9 | protected void onCreate(Bundle savedInstanceState) { 10 | super.onCreate(savedInstanceState); 11 | setContentView(R.layout.activity_behavior_overlap_top); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /app/src/main/java/android/of/road/com/coordinatorlayout/MainActivity.java: -------------------------------------------------------------------------------- 1 | package android.of.road.com.coordinatorlayout; 2 | 3 | import android.content.Intent; 4 | import android.of.road.com.course1.Course1MainActivity; 5 | import android.of.road.com.investment.InvestmentMainActivity; 6 | import android.os.Bundle; 7 | import android.support.design.widget.FloatingActionButton; 8 | import android.support.design.widget.Snackbar; 9 | import android.support.v7.app.AppCompatActivity; 10 | import android.support.v7.widget.Toolbar; 11 | import android.view.Menu; 12 | import android.view.MenuItem; 13 | import android.view.View; 14 | 15 | public class MainActivity extends AppCompatActivity { 16 | 17 | @Override 18 | protected void onCreate(Bundle savedInstanceState) { 19 | super.onCreate(savedInstanceState); 20 | setContentView(R.layout.activity_main); 21 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 22 | setSupportActionBar(toolbar); 23 | 24 | FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); 25 | fab.setOnClickListener(new View.OnClickListener() { 26 | @Override 27 | public void onClick(View view) { 28 | Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) 29 | .setAction("Action", null).show(); 30 | } 31 | }); 32 | } 33 | 34 | @Override 35 | public boolean onCreateOptionsMenu(Menu menu) { 36 | // Inflate the menu; this adds items to the action bar if it is present. 37 | getMenuInflater().inflate(R.menu.menu_main, menu); 38 | return true; 39 | } 40 | 41 | @Override 42 | public boolean onOptionsItemSelected(MenuItem item) { 43 | // Handle action bar item clicks here. The action bar will 44 | // automatically handle clicks on the Home/Up button, so long 45 | // as you specify a parent activity in AndroidManifest.xml. 46 | int id = item.getItemId(); 47 | 48 | //noinspection SimplifiableIfStatement 49 | if (id == R.id.action_settings) { 50 | return true; 51 | } 52 | 53 | return super.onOptionsItemSelected(item); 54 | } 55 | 56 | /** 57 | * 透明 58 | * 59 | * @param view 60 | */ 61 | public void translucentBehavior(View view) { 62 | startActivity(new Intent(this, TranslucentBehaviorActivity.class)); 63 | } 64 | 65 | public void behaviorOverlapTop(View view) { 66 | startActivity(new Intent(this, BehaviorOverlapTopActivity.class)); 67 | 68 | } 69 | 70 | public void transferHeader(View view) { 71 | startActivity(new Intent(this, TransferHeaderActivity.class)); 72 | 73 | } 74 | 75 | public void apayBehavior(View view) { 76 | startActivity(new Intent(this, AlipayBehaviorActivity.class)); 77 | } 78 | 79 | public void serInfo(View view) { 80 | startActivity(new Intent(this, UserInfoActivity.class)); 81 | } 82 | 83 | public void course1Main(View view) { 84 | startActivity(new Intent(this, Course1MainActivity.class)); 85 | 86 | } 87 | 88 | public void elme(View view) { 89 | startActivity(new Intent(this, InvestmentMainActivity.class)); 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /app/src/main/java/android/of/road/com/coordinatorlayout/TransferHeaderActivity.java: -------------------------------------------------------------------------------- 1 | package android.of.road.com.coordinatorlayout; 2 | 3 | import android.support.v7.app.AppCompatActivity; 4 | import android.os.Bundle; 5 | 6 | public class TransferHeaderActivity extends AppCompatActivity { 7 | 8 | @Override 9 | protected void onCreate(Bundle savedInstanceState) { 10 | super.onCreate(savedInstanceState); 11 | setContentView(R.layout.activity_transfer_header); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /app/src/main/java/android/of/road/com/coordinatorlayout/TranslucentBehaviorActivity.java: -------------------------------------------------------------------------------- 1 | package android.of.road.com.coordinatorlayout; 2 | 3 | import android.support.v7.app.AppCompatActivity; 4 | import android.os.Bundle; 5 | 6 | public class TranslucentBehaviorActivity extends AppCompatActivity { 7 | 8 | @Override 9 | protected void onCreate(Bundle savedInstanceState) { 10 | super.onCreate(savedInstanceState); 11 | setContentView(R.layout.activity_translucent_behavior); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /app/src/main/java/android/of/road/com/coordinatorlayout/UserInfoActivity.java: -------------------------------------------------------------------------------- 1 | package android.of.road.com.coordinatorlayout; 2 | 3 | import android.of.road.com.behavior.fragment.UserInfoFragment; 4 | import android.os.Bundle; 5 | import android.support.design.widget.TabLayout; 6 | import android.support.v4.app.Fragment; 7 | import android.support.v4.app.FragmentStatePagerAdapter; 8 | import android.support.v4.view.ViewPager; 9 | import android.support.v7.app.AppCompatActivity; 10 | 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | 14 | public class UserInfoActivity extends AppCompatActivity { 15 | 16 | @Override 17 | protected void onCreate(Bundle savedInstanceState) { 18 | super.onCreate(savedInstanceState); 19 | setContentView(R.layout.activity_user_info); 20 | 21 | initView(); 22 | } 23 | 24 | private void initView() { 25 | TabLayout tlUserInfo = findViewById(R.id.tlUserInfo); 26 | ViewPager vpUserInfo = findViewById(R.id.vpUserInfo); 27 | 28 | final List mFragments = new ArrayList<>(); 29 | mFragments.add(UserInfoFragment.newInstance()); 30 | mFragments.add(UserInfoFragment.newInstance()); 31 | mFragments.add(UserInfoFragment.newInstance()); 32 | 33 | 34 | final String[] title = new String[]{"MEDIA", "ABOUT", "REVIEWS"}; 35 | 36 | vpUserInfo.setAdapter(new FragmentStatePagerAdapter(getSupportFragmentManager()) { 37 | @Override 38 | public Fragment getItem(int position) { 39 | return mFragments.get(position); 40 | } 41 | 42 | @Override 43 | public int getCount() { 44 | return mFragments.size(); 45 | } 46 | 47 | @Override 48 | public CharSequence getPageTitle(int position) { 49 | return title[position]; 50 | } 51 | }); 52 | 53 | vpUserInfo.setOffscreenPageLimit(mFragments.size() * 2); 54 | tlUserInfo.setupWithViewPager(vpUserInfo); 55 | 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /app/src/main/java/android/of/road/com/course1/Course1MainActivity.java: -------------------------------------------------------------------------------- 1 | package android.of.road.com.course1; 2 | 3 | import android.content.Intent; 4 | import android.of.road.com.coordinatorlayout.R; 5 | import android.os.Bundle; 6 | import android.support.v7.app.AppCompatActivity; 7 | import android.view.View; 8 | 9 | public class Course1MainActivity extends AppCompatActivity { 10 | 11 | @Override 12 | protected void onCreate(Bundle savedInstanceState) { 13 | super.onCreate(savedInstanceState); 14 | setContentView(R.layout.activity_course1_main); 15 | } 16 | 17 | /** 18 | * 第一步 19 | * 在XML中使用 20 | * 21 | * @param view 22 | */ 23 | public void createCoordinatorLayout(View view) { 24 | //打开第一个页面 25 | openActivity(CreateCoordinatorLayoutActivity.class); 26 | } 27 | 28 | /** 29 | * 第二步 30 | * 31 | * @param view 32 | */ 33 | public void createAppBarLayout(View view) { 34 | //打开第二个页面 35 | openActivity(CreateAppBarLayoutActivity.class); 36 | } 37 | 38 | public void openActivity(Class activity) { 39 | startActivity(new Intent(this, activity)); 40 | 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /app/src/main/java/android/of/road/com/course1/CreateAppBarLayoutActivity.java: -------------------------------------------------------------------------------- 1 | package android.of.road.com.course1; 2 | 3 | import android.of.road.com.coordinatorlayout.R; 4 | import android.os.Bundle; 5 | import android.support.v7.app.AppCompatActivity; 6 | 7 | public class CreateAppBarLayoutActivity extends AppCompatActivity { 8 | 9 | @Override 10 | protected void onCreate(Bundle savedInstanceState) { 11 | super.onCreate(savedInstanceState); 12 | setContentView(R.layout.activity_create_app_bar_layout); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /app/src/main/java/android/of/road/com/course1/CreateCoordinatorLayoutActivity.java: -------------------------------------------------------------------------------- 1 | package android.of.road.com.course1; 2 | 3 | import android.of.road.com.coordinatorlayout.R; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.os.Bundle; 6 | 7 | public class CreateCoordinatorLayoutActivity extends AppCompatActivity { 8 | 9 | @Override 10 | protected void onCreate(Bundle savedInstanceState) { 11 | super.onCreate(savedInstanceState); 12 | setContentView(R.layout.activity_create_coordinator_layout); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /app/src/main/java/android/of/road/com/investment/InvestmentMainActivity.java: -------------------------------------------------------------------------------- 1 | package android.of.road.com.investment; 2 | 3 | import android.of.road.com.coordinatorlayout.R; 4 | import android.of.road.com.investment.fragment.ShopItemFragment; 5 | import android.of.road.com.investment.fragment.dummy.DummyContent; 6 | import android.of.road.com.investment.utls.StatusBarUtil; 7 | import android.os.Bundle; 8 | import android.support.v4.app.FragmentManager; 9 | import android.support.v4.app.FragmentTransaction; 10 | import android.support.v7.app.AppCompatActivity; 11 | import android.support.v7.widget.Toolbar; 12 | 13 | public class InvestmentMainActivity extends AppCompatActivity implements ShopItemFragment.OnListFragmentInteractionListener { 14 | 15 | @Override 16 | protected void onCreate(Bundle savedInstanceState) { 17 | super.onCreate(savedInstanceState); 18 | setContentView(R.layout.activity_investment_main); 19 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 20 | StatusBarUtil.setTranslucentForImageView(this, 0, null); 21 | setSupportActionBar(toolbar); 22 | 23 | initFragment(); 24 | 25 | } 26 | 27 | private void initFragment() { 28 | FragmentManager supportFragmentManager = getSupportFragmentManager(); 29 | 30 | FragmentTransaction fragmentTransaction = supportFragmentManager.beginTransaction(); 31 | fragmentTransaction.replace(R.id.mShopItemFragment, new ShopItemFragment()); 32 | 33 | 34 | fragmentTransaction.commit(); 35 | 36 | 37 | } 38 | 39 | @Override 40 | public void onListFragmentInteraction(DummyContent.DummyItem item) { 41 | 42 | } 43 | 44 | @Override 45 | public void onPointerCaptureChanged(boolean hasCapture) { 46 | 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /app/src/main/java/android/of/road/com/investment/behavior/MerchantInfoBehavior.java: -------------------------------------------------------------------------------- 1 | package android.of.road.com.investment.behavior; 2 | 3 | import android.content.Context; 4 | import android.of.road.com.behavior.utils.DensityUtils; 5 | import android.of.road.com.coordinatorlayout.R; 6 | import android.support.design.widget.CoordinatorLayout; 7 | import android.util.AttributeSet; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | import android.widget.ImageView; 11 | import android.widget.LinearLayout; 12 | import android.widget.TextView; 13 | 14 | /** 15 | * Created by jc on 2018-08-01. 16 | * Version:1.0 17 | * Description: 18 | * ChangeLog: 19 | */ 20 | public class MerchantInfoBehavior extends CoordinatorLayout.Behavior { 21 | 22 | private ImageView mImageView; 23 | // private TextView mImageView; 24 | private int mOffset = -1; 25 | private int mViewOffsetHeight = -1; 26 | 27 | 28 | /** 29 | * 优惠券 30 | */ 31 | private LinearLayout llCard; 32 | /** 33 | * 根布局 34 | */ 35 | private LinearLayout llMerchantRoot; 36 | 37 | /** 38 | * 优惠券的高度 39 | */ 40 | private int mCardHeight = -1; 41 | /** 42 | * 商家推荐 43 | */ 44 | private TextView mTvMerchantRecord; 45 | /** 46 | * 商检推荐高度 47 | */ 48 | private int mTvMerchantRecordHeight = -1; 49 | 50 | /** 51 | * 商家推荐 文字 52 | */ 53 | private View mMerchantText; 54 | /** 55 | * 商家推荐 高度 56 | */ 57 | private int mMerchantTextHeight = -1; 58 | 59 | public MerchantInfoBehavior(Context context, AttributeSet attrs) { 60 | super(context, attrs); 61 | } 62 | 63 | @Override 64 | public boolean layoutDependsOn(CoordinatorLayout parent, View child, View dependency) { 65 | return super.layoutDependsOn(parent, child, dependency); 66 | } 67 | 68 | @Override 69 | public boolean onDependentViewChanged(CoordinatorLayout parent, View child, View dependency) { 70 | if (mImageView == null) { 71 | mImageView = parent.findViewById(R.id.vImage); 72 | llCard = parent.findViewById(R.id.llCard); 73 | llMerchantRoot = parent.findViewById(R.id.llMerchantRoot); 74 | mTvMerchantRecord = parent.findViewById(R.id.mTvMerchantRecord); 75 | mMerchantText = parent.findViewById(R.id.mMerchantText); 76 | 77 | mCardHeight = llCard.getHeight(); 78 | mTvMerchantRecordHeight = mTvMerchantRecord.getHeight(); 79 | mMerchantTextHeight = mMerchantText.getHeight(); 80 | } 81 | 82 | 83 | //--------------------上面的图片 84 | if (mOffset == -1) { 85 | mOffset = DensityUtils.dp2px(parent.getContext(), 72f); 86 | mViewOffsetHeight = mImageView.getHeight() - mOffset; 87 | } 88 | // 计算百分比 89 | float mTopImagePre = dependency.getY() / mViewOffsetHeight; 90 | if (mTopImagePre >= 1f) { 91 | mTopImagePre = 1f; 92 | } 93 | 94 | // mImageView.setText("" + mTopImagePre); 95 | // 移动Y轴的距离 96 | llMerchantRoot.setY(-(mViewOffsetHeight * mTopImagePre)); 97 | 98 | //--------------------上面的图片 99 | 100 | // -----------更改 优惠券的高度 start 101 | // 上面整块一起滑动 102 | float mCardPre = dependency.getY() / (mImageView.getHeight()); 103 | if (mCardPre > 1) { 104 | mCardPre = 1f; 105 | } 106 | //优惠券 107 | llCard.setAlpha(1 - mCardPre); 108 | ViewGroup.LayoutParams layoutParams = llCard.getLayoutParams(); 109 | layoutParams.height = (int) (mCardHeight - (mCardHeight * mCardPre)); 110 | llCard.setLayoutParams(layoutParams); 111 | // -----------更改 优惠券的高度 start 112 | 113 | 114 | //-------------商家推荐 start 115 | // 参照物,模仿阻尼效果 116 | float mTopImageTagPre = dependency.getY() / mViewOffsetHeight; 117 | 118 | if (mTopImageTagPre > 1.2f) {// 滑动关闭 119 | 120 | // 减去各种各样的高度 121 | float mMearchantPre = (dependency.getY() - mViewOffsetHeight - mCardHeight) / mTvMerchantRecordHeight; 122 | if (mMearchantPre > 1) { 123 | mMearchantPre = 1f; 124 | } 125 | if (mMearchantPre < 0) { 126 | mMearchantPre = 0f; 127 | } 128 | mTvMerchantRecord.setText("" + mMearchantPre); 129 | 130 | //更改高度 131 | ViewGroup.LayoutParams layoutParams1 = mTvMerchantRecord.getLayoutParams(); 132 | layoutParams1.height = (int) (mTvMerchantRecordHeight - (mTvMerchantRecordHeight * mMearchantPre)); 133 | mTvMerchantRecord.setLayoutParams(layoutParams1); 134 | 135 | 136 | // 商家推荐 这几个文字 当 推荐的商品完全关闭以后,进行打开 137 | 138 | 139 | } 140 | 141 | //-------------商家推荐 end 142 | 143 | 144 | return super.onDependentViewChanged(parent, child, dependency); 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /app/src/main/java/android/of/road/com/investment/fragment/MyShopItemRecyclerViewAdapter.java: -------------------------------------------------------------------------------- 1 | package android.of.road.com.investment.fragment; 2 | 3 | import android.of.road.com.coordinatorlayout.R; 4 | import android.of.road.com.investment.fragment.ShopItemFragment.OnListFragmentInteractionListener; 5 | import android.of.road.com.investment.fragment.dummy.DummyContent.DummyItem; 6 | import android.support.v7.widget.RecyclerView; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | import android.widget.TextView; 11 | 12 | import java.util.List; 13 | 14 | /** 15 | * {@link RecyclerView.Adapter} that can display a {@link DummyItem} and makes a call to the 16 | * specified {@link OnListFragmentInteractionListener}. 17 | * TODO: Replace the implementation with code for your data type. 18 | */ 19 | public class MyShopItemRecyclerViewAdapter extends RecyclerView.Adapter { 20 | 21 | private final List mValues; 22 | private final OnListFragmentInteractionListener mListener; 23 | 24 | public MyShopItemRecyclerViewAdapter(List items, OnListFragmentInteractionListener listener) { 25 | mValues = items; 26 | mListener = listener; 27 | } 28 | 29 | @Override 30 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 31 | View view = LayoutInflater.from(parent.getContext()) 32 | .inflate(R.layout.fragment_shopitem, parent, false); 33 | return new ViewHolder(view); 34 | } 35 | 36 | @Override 37 | public void onBindViewHolder(final ViewHolder holder, int position) { 38 | holder.mItem = mValues.get(position); 39 | holder.mIdView.setText(mValues.get(position).id); 40 | holder.mContentView.setText(mValues.get(position).content); 41 | 42 | holder.mView.setOnClickListener(new View.OnClickListener() { 43 | @Override 44 | public void onClick(View v) { 45 | if (null != mListener) { 46 | // Notify the active callbacks interface (the activity, if the 47 | // fragment is attached to one) that an item has been selected. 48 | mListener.onListFragmentInteraction(holder.mItem); 49 | } 50 | } 51 | }); 52 | } 53 | 54 | @Override 55 | public int getItemCount() { 56 | return mValues.size(); 57 | } 58 | 59 | public class ViewHolder extends RecyclerView.ViewHolder { 60 | public final View mView; 61 | public final TextView mIdView; 62 | public final TextView mContentView; 63 | public DummyItem mItem; 64 | 65 | public ViewHolder(View view) { 66 | super(view); 67 | mView = view; 68 | mIdView = (TextView) view.findViewById(R.id.item_number); 69 | mContentView = (TextView) view.findViewById(R.id.content); 70 | } 71 | 72 | @Override 73 | public String toString() { 74 | return super.toString() + " '" + mContentView.getText() + "'"; 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /app/src/main/java/android/of/road/com/investment/fragment/ShopItemFragment.java: -------------------------------------------------------------------------------- 1 | package android.of.road.com.investment.fragment; 2 | 3 | import android.content.Context; 4 | import android.of.road.com.coordinatorlayout.R; 5 | import android.of.road.com.investment.fragment.dummy.DummyContent; 6 | import android.of.road.com.investment.fragment.dummy.DummyContent.DummyItem; 7 | import android.os.Bundle; 8 | import android.support.v4.app.Fragment; 9 | import android.support.v7.widget.GridLayoutManager; 10 | import android.support.v7.widget.LinearLayoutManager; 11 | import android.support.v7.widget.RecyclerView; 12 | import android.view.LayoutInflater; 13 | import android.view.View; 14 | import android.view.ViewGroup; 15 | 16 | /** 17 | * A fragment representing a list of Items. 18 | *

19 | * Activities containing this fragment MUST implement the {@link OnListFragmentInteractionListener} 20 | * interface. 21 | */ 22 | public class ShopItemFragment extends Fragment { 23 | 24 | // TODO: Customize parameters 25 | private int mColumnCount = 3; 26 | 27 | private OnListFragmentInteractionListener mListener; 28 | 29 | /** 30 | * Mandatory empty constructor for the fragment manager to instantiate the 31 | * fragment (e.g. upon screen orientation changes). 32 | */ 33 | public ShopItemFragment() { 34 | } 35 | 36 | @Override 37 | public void onCreate(Bundle savedInstanceState) { 38 | super.onCreate(savedInstanceState); 39 | 40 | } 41 | 42 | @Override 43 | public View onCreateView(LayoutInflater inflater, ViewGroup container, 44 | Bundle savedInstanceState) { 45 | View view = inflater.inflate(R.layout.fragment_shopitem_list, container, false); 46 | 47 | // Set the adapter 48 | if (view instanceof RecyclerView) { 49 | Context context = view.getContext(); 50 | RecyclerView recyclerView = (RecyclerView) view; 51 | if (mColumnCount <= 1) { 52 | recyclerView.setLayoutManager(new LinearLayoutManager(context)); 53 | } else { 54 | recyclerView.setLayoutManager(new GridLayoutManager(context, mColumnCount)); 55 | } 56 | recyclerView.setAdapter(new MyShopItemRecyclerViewAdapter(DummyContent.ITEMS, mListener)); 57 | } 58 | return view; 59 | } 60 | 61 | 62 | @Override 63 | public void onAttach(Context context) { 64 | super.onAttach(context); 65 | if (context instanceof OnListFragmentInteractionListener) { 66 | mListener = (OnListFragmentInteractionListener) context; 67 | } else { 68 | throw new RuntimeException(context.toString() 69 | + " must implement OnListFragmentInteractionListener"); 70 | } 71 | } 72 | 73 | @Override 74 | public void onDetach() { 75 | super.onDetach(); 76 | mListener = null; 77 | } 78 | 79 | /** 80 | * This interface must be implemented by activities that contain this 81 | * fragment to allow an interaction in this fragment to be communicated 82 | * to the activity and potentially other fragments contained in that 83 | * activity. 84 | *

85 | * See the Android Training lesson Communicating with Other Fragments for more information. 88 | */ 89 | public interface OnListFragmentInteractionListener { 90 | // TODO: Update argument type and name 91 | void onListFragmentInteraction(DummyItem item); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /app/src/main/java/android/of/road/com/investment/fragment/dummy/DummyContent.java: -------------------------------------------------------------------------------- 1 | package android.of.road.com.investment.fragment.dummy; 2 | 3 | import java.util.ArrayList; 4 | import java.util.HashMap; 5 | import java.util.List; 6 | import java.util.Map; 7 | 8 | /** 9 | * Helper class for providing sample content for user interfaces created by 10 | * Android template wizards. 11 | *

12 | * TODO: Replace all uses of this class before publishing your app. 13 | */ 14 | public class DummyContent { 15 | 16 | /** 17 | * An array of sample (dummy) items. 18 | */ 19 | public static final List ITEMS = new ArrayList(); 20 | 21 | /** 22 | * A map of sample (dummy) items, by ID. 23 | */ 24 | public static final Map ITEM_MAP = new HashMap(); 25 | 26 | private static final int COUNT = 25; 27 | 28 | static { 29 | // Add some sample items. 30 | for (int i = 1; i <= COUNT; i++) { 31 | addItem(createDummyItem(i)); 32 | } 33 | } 34 | 35 | private static void addItem(DummyItem item) { 36 | ITEMS.add(item); 37 | ITEM_MAP.put(item.id, item); 38 | } 39 | 40 | private static DummyItem createDummyItem(int position) { 41 | return new DummyItem(String.valueOf(position), "Item " + position, makeDetails(position)); 42 | } 43 | 44 | private static String makeDetails(int position) { 45 | StringBuilder builder = new StringBuilder(); 46 | builder.append("Details about Item: ").append(position); 47 | for (int i = 0; i < position; i++) { 48 | builder.append("\nMore details information here."); 49 | } 50 | return builder.toString(); 51 | } 52 | 53 | /** 54 | * A dummy item representing a piece of content. 55 | */ 56 | public static class DummyItem { 57 | public final String id; 58 | public final String content; 59 | public final String details; 60 | 61 | public DummyItem(String id, String content, String details) { 62 | this.id = id; 63 | this.content = content; 64 | this.details = details; 65 | } 66 | 67 | @Override 68 | public String toString() { 69 | return content; 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /app/src/main/java/android/of/road/com/investment/utls/StatusBarUtil.java: -------------------------------------------------------------------------------- 1 | package android.of.road.com.investment.utls; 2 | 3 | import android.annotation.TargetApi; 4 | import android.app.Activity; 5 | import android.content.Context; 6 | import android.graphics.Color; 7 | import android.of.road.com.coordinatorlayout.R; 8 | import android.os.Build; 9 | import android.support.annotation.ColorInt; 10 | import android.support.design.widget.CoordinatorLayout; 11 | import android.support.v4.widget.DrawerLayout; 12 | import android.view.View; 13 | import android.view.ViewGroup; 14 | import android.view.WindowManager; 15 | import android.widget.LinearLayout; 16 | 17 | 18 | 19 | /** 20 | * Created by Jaeger on 16/2/14. 21 | *

22 | * Email: chjie.jaeger@gmail.com 23 | * GitHub: https://github.com/laobie 24 | */ 25 | public class StatusBarUtil { 26 | 27 | public static final int DEFAULT_STATUS_BAR_ALPHA = 112; 28 | private static final int FAKE_STATUS_BAR_VIEW_ID = R.id.statusbarutil_fake_status_bar_view; 29 | private static final int FAKE_TRANSLUCENT_VIEW_ID = R.id.statusbarutil_translucent_view; 30 | private static final int TAG_KEY_HAVE_SET_OFFSET = -123; 31 | 32 | /** 33 | * 设置状态栏颜色 34 | * 35 | * @param activity 需要设置的 activity 36 | * @param color 状态栏颜色值 37 | */ 38 | public static void setColor(Activity activity, @ColorInt int color) { 39 | setColor(activity, color, DEFAULT_STATUS_BAR_ALPHA); 40 | } 41 | 42 | /** 43 | * 设置状态栏颜色 44 | * 45 | * @param activity 需要设置的activity 46 | * @param color 状态栏颜色值 47 | * @param statusBarAlpha 状态栏透明度 48 | */ 49 | 50 | public static void setColor(Activity activity, @ColorInt int color, int statusBarAlpha) { 51 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 52 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); 53 | activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); 54 | activity.getWindow().setStatusBarColor(calculateStatusColor(color, statusBarAlpha)); 55 | } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { 56 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); 57 | ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView(); 58 | View fakeStatusBarView = decorView.findViewById(FAKE_STATUS_BAR_VIEW_ID); 59 | if (fakeStatusBarView != null) { 60 | if (fakeStatusBarView.getVisibility() == View.GONE) { 61 | fakeStatusBarView.setVisibility(View.VISIBLE); 62 | } 63 | fakeStatusBarView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha)); 64 | } else { 65 | decorView.addView(createStatusBarView(activity, color, statusBarAlpha)); 66 | } 67 | setRootView(activity); 68 | } 69 | } 70 | 71 | /** 72 | * 为滑动返回界面设置状态栏颜色 73 | * 74 | * @param activity 需要设置的activity 75 | * @param color 状态栏颜色值 76 | */ 77 | public static void setColorForSwipeBack(Activity activity, int color) { 78 | setColorForSwipeBack(activity, color, DEFAULT_STATUS_BAR_ALPHA); 79 | } 80 | 81 | /** 82 | * 为滑动返回界面设置状态栏颜色 83 | * 84 | * @param activity 需要设置的activity 85 | * @param color 状态栏颜色值 86 | * @param statusBarAlpha 状态栏透明度 87 | */ 88 | public static void setColorForSwipeBack(Activity activity, @ColorInt int color, int statusBarAlpha) { 89 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { 90 | 91 | ViewGroup contentView = ((ViewGroup) activity.findViewById(android.R.id.content)); 92 | View rootView = contentView.getChildAt(0); 93 | int statusBarHeight = getStatusBarHeight(activity); 94 | if (rootView != null && rootView instanceof CoordinatorLayout) { 95 | final CoordinatorLayout coordinatorLayout = (CoordinatorLayout) rootView; 96 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { 97 | coordinatorLayout.setFitsSystemWindows(false); 98 | contentView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha)); 99 | boolean isNeedRequestLayout = contentView.getPaddingTop() < statusBarHeight; 100 | if (isNeedRequestLayout) { 101 | contentView.setPadding(0, statusBarHeight, 0, 0); 102 | coordinatorLayout.post(new Runnable() { 103 | @Override 104 | public void run() { 105 | coordinatorLayout.requestLayout(); 106 | } 107 | }); 108 | } 109 | } else { 110 | coordinatorLayout.setStatusBarBackgroundColor(calculateStatusColor(color, statusBarAlpha)); 111 | } 112 | } else { 113 | contentView.setPadding(0, statusBarHeight, 0, 0); 114 | contentView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha)); 115 | } 116 | setTransparentForWindow(activity); 117 | } 118 | } 119 | 120 | /** 121 | * 设置状态栏纯色 不加半透明效果 122 | * 123 | * @param activity 需要设置的 activity 124 | * @param color 状态栏颜色值 125 | */ 126 | public static void setColorNoTranslucent(Activity activity, @ColorInt int color) { 127 | setColor(activity, color, 0); 128 | } 129 | 130 | /** 131 | * 设置状态栏颜色(5.0以下无半透明效果,不建议使用) 132 | * 133 | * @param activity 需要设置的 activity 134 | * @param color 状态栏颜色值 135 | */ 136 | @Deprecated 137 | public static void setColorDiff(Activity activity, @ColorInt int color) { 138 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { 139 | return; 140 | } 141 | transparentStatusBar(activity); 142 | ViewGroup contentView = (ViewGroup) activity.findViewById(android.R.id.content); 143 | // 移除半透明矩形,以免叠加 144 | View fakeStatusBarView = contentView.findViewById(FAKE_STATUS_BAR_VIEW_ID); 145 | if (fakeStatusBarView != null) { 146 | if (fakeStatusBarView.getVisibility() == View.GONE) { 147 | fakeStatusBarView.setVisibility(View.VISIBLE); 148 | } 149 | fakeStatusBarView.setBackgroundColor(color); 150 | } else { 151 | contentView.addView(createStatusBarView(activity, color)); 152 | } 153 | setRootView(activity); 154 | } 155 | 156 | /** 157 | * 使状态栏半透明 158 | *

159 | * 适用于图片作为背景的界面,此时需要图片填充到状态栏 160 | * 161 | * @param activity 需要设置的activity 162 | */ 163 | public static void setTranslucent(Activity activity) { 164 | setTranslucent(activity, DEFAULT_STATUS_BAR_ALPHA); 165 | } 166 | 167 | /** 168 | * 使状态栏半透明 169 | *

170 | * 适用于图片作为背景的界面,此时需要图片填充到状态栏 171 | * 172 | * @param activity 需要设置的activity 173 | * @param statusBarAlpha 状态栏透明度 174 | */ 175 | public static void setTranslucent(Activity activity, int statusBarAlpha) { 176 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { 177 | return; 178 | } 179 | setTransparent(activity); 180 | addTranslucentView(activity, statusBarAlpha); 181 | } 182 | 183 | /** 184 | * 针对根布局是 CoordinatorLayout, 使状态栏半透明 185 | *

186 | * 适用于图片作为背景的界面,此时需要图片填充到状态栏 187 | * 188 | * @param activity 需要设置的activity 189 | * @param statusBarAlpha 状态栏透明度 190 | */ 191 | public static void setTranslucentForCoordinatorLayout(Activity activity, int statusBarAlpha) { 192 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { 193 | return; 194 | } 195 | transparentStatusBar(activity); 196 | addTranslucentView(activity, statusBarAlpha); 197 | } 198 | 199 | /** 200 | * 设置状态栏全透明 201 | * 202 | * @param activity 需要设置的activity 203 | */ 204 | public static void setTransparent(Activity activity) { 205 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { 206 | return; 207 | } 208 | transparentStatusBar(activity); 209 | setRootView(activity); 210 | } 211 | 212 | /** 213 | * 使状态栏透明(5.0以上半透明效果,不建议使用) 214 | *

215 | * 适用于图片作为背景的界面,此时需要图片填充到状态栏 216 | * 217 | * @param activity 需要设置的activity 218 | */ 219 | @Deprecated 220 | public static void setTranslucentDiff(Activity activity) { 221 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { 222 | // 设置状态栏透明 223 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); 224 | setRootView(activity); 225 | } 226 | } 227 | 228 | /** 229 | * 为DrawerLayout 布局设置状态栏变色 230 | * 231 | * @param activity 需要设置的activity 232 | * @param drawerLayout DrawerLayout 233 | * @param color 状态栏颜色值 234 | */ 235 | public static void setColorForDrawerLayout(Activity activity, DrawerLayout drawerLayout, @ColorInt int color) { 236 | setColorForDrawerLayout(activity, drawerLayout, color, DEFAULT_STATUS_BAR_ALPHA); 237 | } 238 | 239 | /** 240 | * 为DrawerLayout 布局设置状态栏颜色,纯色 241 | * 242 | * @param activity 需要设置的activity 243 | * @param drawerLayout DrawerLayout 244 | * @param color 状态栏颜色值 245 | */ 246 | public static void setColorNoTranslucentForDrawerLayout(Activity activity, DrawerLayout drawerLayout, @ColorInt int color) { 247 | setColorForDrawerLayout(activity, drawerLayout, color, 0); 248 | } 249 | 250 | /** 251 | * 为DrawerLayout 布局设置状态栏变色 252 | * 253 | * @param activity 需要设置的activity 254 | * @param drawerLayout DrawerLayout 255 | * @param color 状态栏颜色值 256 | * @param statusBarAlpha 状态栏透明度 257 | */ 258 | public static void setColorForDrawerLayout(Activity activity, DrawerLayout drawerLayout, @ColorInt int color, 259 | int statusBarAlpha) { 260 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { 261 | return; 262 | } 263 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 264 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); 265 | activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); 266 | activity.getWindow().setStatusBarColor(Color.TRANSPARENT); 267 | } else { 268 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); 269 | } 270 | // 生成一个状态栏大小的矩形 271 | // 添加 statusBarView 到布局中 272 | ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0); 273 | View fakeStatusBarView = contentLayout.findViewById(FAKE_STATUS_BAR_VIEW_ID); 274 | if (fakeStatusBarView != null) { 275 | if (fakeStatusBarView.getVisibility() == View.GONE) { 276 | fakeStatusBarView.setVisibility(View.VISIBLE); 277 | } 278 | fakeStatusBarView.setBackgroundColor(color); 279 | } else { 280 | contentLayout.addView(createStatusBarView(activity, color), 0); 281 | } 282 | // 内容布局不是 LinearLayout 时,设置padding top 283 | if (!(contentLayout instanceof LinearLayout) && contentLayout.getChildAt(1) != null) { 284 | contentLayout.getChildAt(1) 285 | .setPadding(contentLayout.getPaddingLeft(), getStatusBarHeight(activity) + contentLayout.getPaddingTop(), 286 | contentLayout.getPaddingRight(), contentLayout.getPaddingBottom()); 287 | } 288 | // 设置属性 289 | setDrawerLayoutProperty(drawerLayout, contentLayout); 290 | addTranslucentView(activity, statusBarAlpha); 291 | } 292 | 293 | /** 294 | * 设置 DrawerLayout 属性 295 | * 296 | * @param drawerLayout DrawerLayout 297 | * @param drawerLayoutContentLayout DrawerLayout 的内容布局 298 | */ 299 | private static void setDrawerLayoutProperty(DrawerLayout drawerLayout, ViewGroup drawerLayoutContentLayout) { 300 | ViewGroup drawer = (ViewGroup) drawerLayout.getChildAt(1); 301 | drawerLayout.setFitsSystemWindows(false); 302 | drawerLayoutContentLayout.setFitsSystemWindows(false); 303 | drawerLayoutContentLayout.setClipToPadding(true); 304 | drawer.setFitsSystemWindows(false); 305 | } 306 | 307 | /** 308 | * 为DrawerLayout 布局设置状态栏变色(5.0以下无半透明效果,不建议使用) 309 | * 310 | * @param activity 需要设置的activity 311 | * @param drawerLayout DrawerLayout 312 | * @param color 状态栏颜色值 313 | */ 314 | @Deprecated 315 | public static void setColorForDrawerLayoutDiff(Activity activity, DrawerLayout drawerLayout, @ColorInt int color) { 316 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { 317 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); 318 | // 生成一个状态栏大小的矩形 319 | ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0); 320 | View fakeStatusBarView = contentLayout.findViewById(FAKE_STATUS_BAR_VIEW_ID); 321 | if (fakeStatusBarView != null) { 322 | if (fakeStatusBarView.getVisibility() == View.GONE) { 323 | fakeStatusBarView.setVisibility(View.VISIBLE); 324 | } 325 | fakeStatusBarView.setBackgroundColor(calculateStatusColor(color, DEFAULT_STATUS_BAR_ALPHA)); 326 | } else { 327 | // 添加 statusBarView 到布局中 328 | contentLayout.addView(createStatusBarView(activity, color), 0); 329 | } 330 | // 内容布局不是 LinearLayout 时,设置padding top 331 | if (!(contentLayout instanceof LinearLayout) && contentLayout.getChildAt(1) != null) { 332 | contentLayout.getChildAt(1).setPadding(0, getStatusBarHeight(activity), 0, 0); 333 | } 334 | // 设置属性 335 | setDrawerLayoutProperty(drawerLayout, contentLayout); 336 | } 337 | } 338 | 339 | /** 340 | * 为 DrawerLayout 布局设置状态栏透明 341 | * 342 | * @param activity 需要设置的activity 343 | * @param drawerLayout DrawerLayout 344 | */ 345 | public static void setTranslucentForDrawerLayout(Activity activity, DrawerLayout drawerLayout) { 346 | setTranslucentForDrawerLayout(activity, drawerLayout, DEFAULT_STATUS_BAR_ALPHA); 347 | } 348 | 349 | /** 350 | * 为 DrawerLayout 布局设置状态栏透明 351 | * 352 | * @param activity 需要设置的activity 353 | * @param drawerLayout DrawerLayout 354 | */ 355 | public static void setTranslucentForDrawerLayout(Activity activity, DrawerLayout drawerLayout, int statusBarAlpha) { 356 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { 357 | return; 358 | } 359 | setTransparentForDrawerLayout(activity, drawerLayout); 360 | addTranslucentView(activity, statusBarAlpha); 361 | } 362 | 363 | /** 364 | * 为 DrawerLayout 布局设置状态栏透明 365 | * 366 | * @param activity 需要设置的activity 367 | * @param drawerLayout DrawerLayout 368 | */ 369 | public static void setTransparentForDrawerLayout(Activity activity, DrawerLayout drawerLayout) { 370 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { 371 | return; 372 | } 373 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 374 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); 375 | activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); 376 | activity.getWindow().setStatusBarColor(Color.TRANSPARENT); 377 | } else { 378 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); 379 | } 380 | 381 | ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0); 382 | // 内容布局不是 LinearLayout 时,设置padding top 383 | if (!(contentLayout instanceof LinearLayout) && contentLayout.getChildAt(1) != null) { 384 | contentLayout.getChildAt(1).setPadding(0, getStatusBarHeight(activity), 0, 0); 385 | } 386 | 387 | // 设置属性 388 | setDrawerLayoutProperty(drawerLayout, contentLayout); 389 | } 390 | 391 | /** 392 | * 为 DrawerLayout 布局设置状态栏透明(5.0以上半透明效果,不建议使用) 393 | * 394 | * @param activity 需要设置的activity 395 | * @param drawerLayout DrawerLayout 396 | */ 397 | @Deprecated 398 | public static void setTranslucentForDrawerLayoutDiff(Activity activity, DrawerLayout drawerLayout) { 399 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { 400 | // 设置状态栏透明 401 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); 402 | // 设置内容布局属性 403 | ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0); 404 | contentLayout.setFitsSystemWindows(true); 405 | contentLayout.setClipToPadding(true); 406 | // 设置抽屉布局属性 407 | ViewGroup vg = (ViewGroup) drawerLayout.getChildAt(1); 408 | vg.setFitsSystemWindows(false); 409 | // 设置 DrawerLayout 属性 410 | drawerLayout.setFitsSystemWindows(false); 411 | } 412 | } 413 | 414 | /** 415 | * 为头部是 ImageView 的界面设置状态栏全透明 416 | * 417 | * @param activity 需要设置的activity 418 | * @param needOffsetView 需要向下偏移的 View 419 | */ 420 | public static void setTransparentForImageView(Activity activity, View needOffsetView) { 421 | setTranslucentForImageView(activity, 0, needOffsetView); 422 | } 423 | 424 | /** 425 | * 为头部是 ImageView 的界面设置状态栏透明(使用默认透明度) 426 | * 427 | * @param activity 需要设置的activity 428 | * @param needOffsetView 需要向下偏移的 View 429 | */ 430 | public static void setTranslucentForImageView(Activity activity, View needOffsetView) { 431 | setTranslucentForImageView(activity, DEFAULT_STATUS_BAR_ALPHA, needOffsetView); 432 | } 433 | 434 | /** 435 | * 为头部是 ImageView 的界面设置状态栏透明 436 | * 437 | * @param activity 需要设置的activity 438 | * @param statusBarAlpha 状态栏透明度 439 | * @param needOffsetView 需要向下偏移的 View 440 | */ 441 | public static void setTranslucentForImageView(Activity activity, int statusBarAlpha, View needOffsetView) { 442 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { 443 | return; 444 | } 445 | setTransparentForWindow(activity); 446 | addTranslucentView(activity, statusBarAlpha); 447 | if (needOffsetView != null) { 448 | Object haveSetOffset = needOffsetView.getTag(TAG_KEY_HAVE_SET_OFFSET); 449 | if (haveSetOffset != null && (Boolean) haveSetOffset) { 450 | return; 451 | } 452 | ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) needOffsetView.getLayoutParams(); 453 | layoutParams.setMargins(layoutParams.leftMargin, layoutParams.topMargin + getStatusBarHeight(activity), 454 | layoutParams.rightMargin, layoutParams.bottomMargin); 455 | needOffsetView.setTag(TAG_KEY_HAVE_SET_OFFSET, true); 456 | } 457 | } 458 | 459 | /** 460 | * 为 fragment 头部是 ImageView 的设置状态栏透明 461 | * 462 | * @param activity fragment 对应的 activity 463 | * @param needOffsetView 需要向下偏移的 View 464 | */ 465 | public static void setTranslucentForImageViewInFragment(Activity activity, View needOffsetView) { 466 | setTranslucentForImageViewInFragment(activity, DEFAULT_STATUS_BAR_ALPHA, needOffsetView); 467 | } 468 | 469 | /** 470 | * 为 fragment 头部是 ImageView 的设置状态栏透明 471 | * 472 | * @param activity fragment 对应的 activity 473 | * @param needOffsetView 需要向下偏移的 View 474 | */ 475 | public static void setTransparentForImageViewInFragment(Activity activity, View needOffsetView) { 476 | setTranslucentForImageViewInFragment(activity, 0, needOffsetView); 477 | } 478 | 479 | /** 480 | * 为 fragment 头部是 ImageView 的设置状态栏透明 481 | * 482 | * @param activity fragment 对应的 activity 483 | * @param statusBarAlpha 状态栏透明度 484 | * @param needOffsetView 需要向下偏移的 View 485 | */ 486 | public static void setTranslucentForImageViewInFragment(Activity activity, int statusBarAlpha, View needOffsetView) { 487 | setTranslucentForImageView(activity, statusBarAlpha, needOffsetView); 488 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { 489 | clearPreviousSetting(activity); 490 | } 491 | } 492 | 493 | /** 494 | * 隐藏伪状态栏 View 495 | * 496 | * @param activity 调用的 Activity 497 | */ 498 | public static void hideFakeStatusBarView(Activity activity) { 499 | ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView(); 500 | View fakeStatusBarView = decorView.findViewById(FAKE_STATUS_BAR_VIEW_ID); 501 | if (fakeStatusBarView != null) { 502 | fakeStatusBarView.setVisibility(View.GONE); 503 | } 504 | View fakeTranslucentView = decorView.findViewById(FAKE_TRANSLUCENT_VIEW_ID); 505 | if (fakeTranslucentView != null) { 506 | fakeTranslucentView.setVisibility(View.GONE); 507 | } 508 | } 509 | 510 | /////////////////////////////////////////////////////////////////////////////////// 511 | 512 | @TargetApi(Build.VERSION_CODES.KITKAT) 513 | private static void clearPreviousSetting(Activity activity) { 514 | ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView(); 515 | View fakeStatusBarView = decorView.findViewById(FAKE_STATUS_BAR_VIEW_ID); 516 | if (fakeStatusBarView != null) { 517 | decorView.removeView(fakeStatusBarView); 518 | ViewGroup rootView = (ViewGroup) ((ViewGroup) activity.findViewById(android.R.id.content)).getChildAt(0); 519 | rootView.setPadding(0, 0, 0, 0); 520 | } 521 | } 522 | 523 | /** 524 | * 添加半透明矩形条 525 | * 526 | * @param activity 需要设置的 activity 527 | * @param statusBarAlpha 透明值 528 | */ 529 | private static void addTranslucentView(Activity activity, int statusBarAlpha) { 530 | ViewGroup contentView = (ViewGroup) activity.findViewById(android.R.id.content); 531 | View fakeTranslucentView = contentView.findViewById(FAKE_TRANSLUCENT_VIEW_ID); 532 | if (fakeTranslucentView != null) { 533 | if (fakeTranslucentView.getVisibility() == View.GONE) { 534 | fakeTranslucentView.setVisibility(View.VISIBLE); 535 | } 536 | fakeTranslucentView.setBackgroundColor(Color.argb(statusBarAlpha, 0, 0, 0)); 537 | } else { 538 | contentView.addView(createTranslucentStatusBarView(activity, statusBarAlpha)); 539 | } 540 | } 541 | 542 | /** 543 | * 生成一个和状态栏大小相同的彩色矩形条 544 | * 545 | * @param activity 需要设置的 activity 546 | * @param color 状态栏颜色值 547 | * @return 状态栏矩形条 548 | */ 549 | private static View createStatusBarView(Activity activity, @ColorInt int color) { 550 | return createStatusBarView(activity, color, 0); 551 | } 552 | 553 | /** 554 | * 生成一个和状态栏大小相同的半透明矩形条 555 | * 556 | * @param activity 需要设置的activity 557 | * @param color 状态栏颜色值 558 | * @param alpha 透明值 559 | * @return 状态栏矩形条 560 | */ 561 | private static View createStatusBarView(Activity activity, @ColorInt int color, int alpha) { 562 | // 绘制一个和状态栏一样高的矩形 563 | View statusBarView = new View(activity); 564 | LinearLayout.LayoutParams params = 565 | new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, getStatusBarHeight(activity)); 566 | statusBarView.setLayoutParams(params); 567 | statusBarView.setBackgroundColor(calculateStatusColor(color, alpha)); 568 | statusBarView.setId(FAKE_STATUS_BAR_VIEW_ID); 569 | return statusBarView; 570 | } 571 | 572 | /** 573 | * 创建一个视图 574 | * @param backId 575 | * @param activity 576 | * @return 577 | */ 578 | public static View createStatusBarView(int backId,Activity activity) { 579 | // 绘制一个和状态栏一样高的矩形 580 | View statusBarView = new View(activity); 581 | LinearLayout.LayoutParams params = 582 | new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, getStatusBarHeight(activity)); 583 | statusBarView.setLayoutParams(params); 584 | statusBarView.setBackgroundResource(backId); 585 | statusBarView.setId(FAKE_STATUS_BAR_VIEW_ID); 586 | return statusBarView; 587 | } 588 | 589 | /** 590 | * 设置根布局参数 591 | */ 592 | private static void setRootView(Activity activity) { 593 | ViewGroup parent = (ViewGroup) activity.findViewById(android.R.id.content); 594 | for (int i = 0, count = parent.getChildCount(); i < count; i++) { 595 | View childView = parent.getChildAt(i); 596 | if (childView instanceof ViewGroup) { 597 | childView.setFitsSystemWindows(true); 598 | ((ViewGroup) childView).setClipToPadding(true); 599 | } 600 | } 601 | } 602 | 603 | /** 604 | * 设置透明 605 | */ 606 | private static void setTransparentForWindow(Activity activity) { 607 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 608 | activity.getWindow().setStatusBarColor(Color.TRANSPARENT); 609 | activity.getWindow() 610 | .getDecorView() 611 | .setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); 612 | } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { 613 | activity.getWindow() 614 | .setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); 615 | } 616 | } 617 | 618 | /** 619 | * 使状态栏透明 620 | */ 621 | @TargetApi(Build.VERSION_CODES.KITKAT) 622 | private static void transparentStatusBar(Activity activity) { 623 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 624 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); 625 | activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); 626 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); 627 | activity.getWindow().setStatusBarColor(Color.TRANSPARENT); 628 | } else { 629 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); 630 | } 631 | } 632 | 633 | /** 634 | * 创建半透明矩形 View 635 | * 636 | * @param alpha 透明值 637 | * @return 半透明 View 638 | */ 639 | private static View createTranslucentStatusBarView(Activity activity, int alpha) { 640 | // 绘制一个和状态栏一样高的矩形 641 | View statusBarView = new View(activity); 642 | LinearLayout.LayoutParams params = 643 | new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, getStatusBarHeight(activity)); 644 | statusBarView.setLayoutParams(params); 645 | statusBarView.setBackgroundColor(Color.argb(alpha, 0, 0, 0)); 646 | statusBarView.setId(FAKE_TRANSLUCENT_VIEW_ID); 647 | return statusBarView; 648 | } 649 | 650 | /** 651 | * 获取状态栏高度 652 | * 653 | * @param context context 654 | * @return 状态栏高度 655 | */ 656 | public static int getStatusBarHeight(Context context) { 657 | // 获得状态栏高度 658 | int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android"); 659 | return context.getResources().getDimensionPixelSize(resourceId); 660 | } 661 | 662 | /** 663 | * 计算状态栏颜色 664 | * 665 | * @param color color值 666 | * @param alpha alpha值 667 | * @return 最终的状态栏颜色 668 | */ 669 | private static int calculateStatusColor(@ColorInt int color, int alpha) { 670 | if (alpha == 0) { 671 | return color; 672 | } 673 | float a = 1 - alpha / 255f; 674 | int red = color >> 16 & 0xff; 675 | int green = color >> 8 & 0xff; 676 | int blue = color & 0xff; 677 | red = (int) (red * a + 0.5); 678 | green = (int) (green * a + 0.5); 679 | blue = (int) (blue * a + 0.5); 680 | return 0xff << 24 | red << 16 | green << 8 | blue; 681 | } 682 | } -------------------------------------------------------------------------------- /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/drawable/background_user_left_action.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 8 | 9 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/background_user_right_action.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 8 | 9 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/background_user_star.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_arrow_back_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 7 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_arrow_back_white_24dp.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_call_24dp.xml: -------------------------------------------------------------------------------- 1 | 7 | 10 | 11 | -------------------------------------------------------------------------------- /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/res/drawable/ic_message_24dp.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_star_white_24dp.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_apay_behavior.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 13 | 14 | 19 | 20 | 21 | 27 | 28 | 29 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 50 | 51 | 54 | 55 | 58 | 59 | 60 | 66 | 67 | 70 | 71 | 74 | 75 | 76 | 82 | 83 | 86 | 87 | 90 | 91 | 92 | 98 | 99 | 102 | 103 | 106 | 107 | 108 | 109 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_behavior_overlap_top.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 14 | 15 | 19 | 20 | 21 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_course1_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 14 | 15 | 19 | 20 | 21 | 22 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_create_app_bar_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 13 | 14 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_create_coordinator_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_investment_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 14 | 15 | 20 | 21 | 22 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 46 | 47 | 50 | 51 | 61 | 62 | 63 | 64 | 70 | 71 | 77 | 78 | 84 | 85 | 91 | 92 | 93 | 94 | 95 | 103 | 104 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 130 | 131 | 132 | 133 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 13 | 14 | 20 | 21 | 22 | 23 | 24 | 25 | 32 | 33 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_transfer_header.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 12 | 13 | 18 | 19 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 41 | 42 | 43 | 44 | 52 | 53 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_translucent_behavior.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 14 | 15 | 20 | 21 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 45 | 46 | 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_user_info.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 13 | 14 | 20 | 21 | 25 | 26 | 27 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 51 | 52 | 58 | 59 | 65 | 66 | 72 | 73 | 79 | 80 | 81 | 87 | 88 | 94 | 95 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 120 | 121 | 127 | 128 | 129 | 135 | 136 | 144 | 145 | 146 | 153 | 154 | 160 | 161 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 184 | 185 | 186 | 194 | 195 | 199 | 200 | 206 | 207 | 208 | 209 | 217 | 218 | 222 | 223 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | -------------------------------------------------------------------------------- /app/src/main/res/layout/content_investment_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /app/src/main/res/layout/content_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 17 | 18 | 19 | 20 | 28 | 29 | 33 | 34 | 42 | 43 | 47 | 48 | 56 | 57 | 61 | 62 | 70 | 71 | 75 | 76 | 84 | 85 | 89 | 97 | 98 | 102 | 103 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_shopitem.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 13 | 14 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_shopitem_list.xml: -------------------------------------------------------------------------------- 1 | 2 | 14 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_user_info.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 12 | 13 | 21 | 22 | 30 | 31 | 39 | 40 | 48 | 49 | 57 | 58 | 66 | 67 | 68 | 76 | 77 | 78 | 86 | 87 | 88 | 96 | 97 | 98 | 106 | 107 | 108 | 109 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_apay_content.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 12 | 13 | 17 | 18 | 26 | 27 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_behavior_overlap_top_content.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 16 | 17 | 24 | 25 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_scroll_content.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 15 | 16 | 24 | 25 | 33 | 34 | 42 | 43 | 51 | 52 | 60 | 61 | 69 | 77 | 78 | 86 | 87 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_tr_content.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | 14 | 18 | 19 | 26 | 27 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_user_info_content.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/res/layout/line_item_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /app/src/main/res/menu/menu_main.xml: -------------------------------------------------------------------------------- 1 |

5 | 10 | 11 | -------------------------------------------------------------------------------- /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/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aohanyao/CoordinatorLayout/52afe442e4fb6277e8b5c6ccb84f4fbd088cdfd6/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aohanyao/CoordinatorLayout/52afe442e4fb6277e8b5c6ccb84f4fbd088cdfd6/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aohanyao/CoordinatorLayout/52afe442e4fb6277e8b5c6ccb84f4fbd088cdfd6/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aohanyao/CoordinatorLayout/52afe442e4fb6277e8b5c6ccb84f4fbd088cdfd6/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aohanyao/CoordinatorLayout/52afe442e4fb6277e8b5c6ccb84f4fbd088cdfd6/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aohanyao/CoordinatorLayout/52afe442e4fb6277e8b5c6ccb84f4fbd088cdfd6/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/default_header.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aohanyao/CoordinatorLayout/52afe442e4fb6277e8b5c6ccb84f4fbd088cdfd6/app/src/main/res/mipmap-xxhdpi/default_header.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/design.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aohanyao/CoordinatorLayout/52afe442e4fb6277e8b5c6ccb84f4fbd088cdfd6/app/src/main/res/mipmap-xxhdpi/design.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aohanyao/CoordinatorLayout/52afe442e4fb6277e8b5c6ccb84f4fbd088cdfd6/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aohanyao/CoordinatorLayout/52afe442e4fb6277e8b5c6ccb84f4fbd088cdfd6/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/icon_card.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aohanyao/CoordinatorLayout/52afe442e4fb6277e8b5c6ccb84f4fbd088cdfd6/app/src/main/res/mipmap-xxhdpi/icon_card.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/icon_pay.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aohanyao/CoordinatorLayout/52afe442e4fb6277e8b5c6ccb84f4fbd088cdfd6/app/src/main/res/mipmap-xxhdpi/icon_pay.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/icon_scanf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aohanyao/CoordinatorLayout/52afe442e4fb6277e8b5c6ccb84f4fbd088cdfd6/app/src/main/res/mipmap-xxhdpi/icon_scanf.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/icon_shoupay.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aohanyao/CoordinatorLayout/52afe442e4fb6277e8b5c6ccb84f4fbd088cdfd6/app/src/main/res/mipmap-xxhdpi/icon_shoupay.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aohanyao/CoordinatorLayout/52afe442e4fb6277e8b5c6ccb84f4fbd088cdfd6/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aohanyao/CoordinatorLayout/52afe442e4fb6277e8b5c6ccb84f4fbd088cdfd6/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/icon_server_app_card.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aohanyao/CoordinatorLayout/52afe442e4fb6277e8b5c6ccb84f4fbd088cdfd6/app/src/main/res/mipmap-xxxhdpi/icon_server_app_card.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/icon_server_app_door.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aohanyao/CoordinatorLayout/52afe442e4fb6277e8b5c6ccb84f4fbd088cdfd6/app/src/main/res/mipmap-xxxhdpi/icon_server_app_door.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/icon_server_app_scanf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aohanyao/CoordinatorLayout/52afe442e4fb6277e8b5c6ccb84f4fbd088cdfd6/app/src/main/res/mipmap-xxxhdpi/icon_server_app_scanf.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/icon_server_app_wallet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aohanyao/CoordinatorLayout/52afe442e4fb6277e8b5c6ccb84f4fbd088cdfd6/app/src/main/res/mipmap-xxxhdpi/icon_server_app_wallet.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 16dp 3 | 16dp 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/values/sb_ids.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Behavior demo 3 | Settings 4 | 5 | 6 | Hello blank fragment 7 | InvestmentMainActivity 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 15 | 16 | 31 | 32 | 39 | 40 | 44 | 45 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /app/src/test/java/android/of/road/com/coordinatorlayout/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package android.of.road.com.coordinatorlayout; 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() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | 5 | repositories { 6 | google() 7 | jcenter() 8 | } 9 | dependencies { 10 | classpath 'com.android.tools.build:gradle:3.1.3' 11 | 12 | 13 | // NOTE: Do not place your application dependencies here; they belong 14 | // in the individual module build.gradle files 15 | } 16 | } 17 | 18 | allprojects { 19 | repositories { 20 | maven { url "https://jitpack.io" } 21 | google() 22 | jcenter() 23 | } 24 | } 25 | 26 | task clean(type: Delete) { 27 | delete rootProject.buildDir 28 | } 29 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aohanyao/CoordinatorLayout/52afe442e4fb6277e8b5c6ccb84f4fbd088cdfd6/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu Jul 12 17:28:46 CST 2018 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.4-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /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 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 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 Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /userinfo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aohanyao/CoordinatorLayout/52afe442e4fb6277e8b5c6ccb84f4fbd088cdfd6/userinfo.gif --------------------------------------------------------------------------------