├── .gitignore ├── LICENSE ├── README.md ├── README_EN.md ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ └── gradle-wrapper.properties ├── sample ├── .gitignore ├── build.gradle ├── proguard-rules.pro ├── sample.iml └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── stx │ │ └── xhb │ │ └── demo │ │ ├── ClipChildrenModeActivity.java │ │ ├── CustomViewsActivity.java │ │ ├── GuideActivity.java │ │ ├── ListViewActivity.java │ │ ├── MainActivity.java │ │ ├── MyApplication.java │ │ ├── RecyclerViewActivity.java │ │ ├── ScreenUtil.java │ │ ├── UserInFragmentActivity.java │ │ ├── VideoViewActivity.java │ │ ├── adapter │ │ └── RvListAdapter.java │ │ ├── entity │ │ ├── CustomViewsInfo.java │ │ ├── ImagesBean.java │ │ └── TuchongEntity.java │ │ ├── fragment │ │ ├── BannerFragment.java │ │ └── NumberIndicatorFragment.java │ │ └── holder │ │ ├── BannerHolderCreator.java │ │ ├── ImageViewHolder.java │ │ └── VideoViewHolder.java │ └── res │ ├── drawable │ ├── banner_placeholder.jpg │ ├── default_image.png │ ├── point_normal.xml │ ├── point_now.xml │ ├── shape_noraml.xml │ ├── shape_number_indicator_background.xml │ ├── shape_round_8dp.xml │ └── shape_selected.xml │ ├── layout │ ├── activity_clip_children_mode.xml │ ├── activity_custom_views.xml │ ├── activity_listview.xml │ ├── activity_main.xml │ ├── activity_recyclerview.xml │ ├── activity_splash.xml │ ├── activity_user_in_fragment.xml │ ├── ad_head.xml │ ├── fragment_banner.xml │ ├── fragment_banner_indicator.xml │ ├── layout_custom_view.xml │ ├── layout_fresco_imageview.xml │ ├── layout_image_view.xml │ ├── layout_video_view.xml │ └── list_item_text.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ ├── ic_launcher.png │ ├── we1.png │ ├── we2.png │ ├── we3.png │ └── xbanner_logo.png │ ├── mipmap-xxxhdpi │ └── ic_launcher.png │ ├── values-w820dp │ └── dimens.xml │ ├── values │ ├── colors.xml │ ├── dimens.xml │ ├── ids.xml │ ├── strings.xml │ └── styles.xml │ └── xml │ └── network_security_config.xml ├── sceenshots ├── apk_code.png ├── overlap.png ├── screenshot1.png ├── screenshot2.png ├── screenshot3.png ├── screenshot4.png ├── screenshot5.png ├── screenshot6.png ├── screenshot7.png └── xbanner.png ├── settings.gradle └── xbanner ├── build.gradle ├── proguard-rules.pro ├── src └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── stx │ │ └── xhb │ │ └── xbanner │ │ ├── XBanner.java │ │ ├── XBannerScroller.java │ │ ├── XBannerUtils.java │ │ ├── XBannerViewPager.java │ │ ├── entity │ │ ├── BaseBannerInfo.java │ │ ├── LocalImageInfo.java │ │ └── SimpleBannerInfo.java │ │ ├── holder │ │ ├── HolderCreator.java │ │ └── ViewHolder.java │ │ ├── listener │ │ └── OnDoubleClickListener.java │ │ └── transformers │ │ ├── AccordionPageTransformer.java │ │ ├── AlphaPageTransformer.java │ │ ├── BasePageTransformer.java │ │ ├── CubePageTransformer.java │ │ ├── DefaultPageTransformer.java │ │ ├── DepthPageTransformer.java │ │ ├── FlipPageTransformer.java │ │ ├── OverLapPageTransformer.java │ │ ├── RotatePageTransformer.java │ │ ├── ScalePageTransformer.java │ │ ├── StackPageTransformer.java │ │ ├── Transformer.java │ │ ├── ZoomCenterPageTransformer.java │ │ ├── ZoomFadePageTransformer.java │ │ ├── ZoomPageTransformer.java │ │ └── ZoomStackPageTransformer.java │ └── res │ ├── drawable │ ├── shape_point_normal.xml │ └── shape_point_select.xml │ ├── layout │ └── xbanner_item_image.xml │ └── values │ ├── attrs.xml │ ├── ids.xml │ └── strings.xml └── xbanner.iml /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### Android template 3 | # Built application files 4 | *.apk 5 | *.ap_ 6 | *.aab 7 | 8 | # Files for the ART/Dalvik VM 9 | *.dex 10 | 11 | # Java class files 12 | *.class 13 | 14 | # Generated files 15 | bin/ 16 | gen/ 17 | out/ 18 | release/ 19 | 20 | # Gradle files 21 | .gradle/ 22 | build/ 23 | 24 | # Local configuration file (sdk path, etc) 25 | local.properties 26 | 27 | # Proguard folder generated by Eclipse 28 | proguard/ 29 | 30 | # Log Files 31 | *.log 32 | 33 | # Android Studio Navigation editor temp files 34 | .navigation/ 35 | 36 | # Android Studio captures folder 37 | captures/ 38 | 39 | # IntelliJ 40 | *.iml 41 | .idea 42 | .idea/tasks.xml 43 | .idea/assetWizardSettings.xml 44 | .idea/dictionaries 45 | # Android Studio 3 in .gitignore file. 46 | # Comment next line if keeping position of elements in Navigation Editor is relevant for you 47 | .idea/navEditor.xml 48 | 49 | # Keystore files 50 | # Uncomment the following lines if you do not want to check your keystore files in. 51 | #*.jks 52 | #*.keystore 53 | 54 | # External native build folder generated in Android Studio 2.2 and later 55 | .externalNativeBuild 56 | 57 | # Google Services (e.g. APIs or Firebase) 58 | # google-services.json 59 | 60 | # Freeline 61 | freeline.py 62 | freeline/ 63 | freeline_project_description.json 64 | 65 | # fastlane 66 | fastlane/report.xml 67 | fastlane/Preview.html 68 | fastlane/screenshots 69 | fastlane/test_output 70 | fastlane/readme.md 71 | 72 | # Version control 73 | vcs.xml 74 | 75 | # lint 76 | lint/intermediates/ 77 | lint/generated/ 78 | lint/outputs/ 79 | lint/tmp/ 80 | # lint/reports/ 81 | 82 | XBanner.iml 83 | xbanner/build/ 84 | -------------------------------------------------------------------------------- /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 | ## XBanner 2 | 3 | [![License](https://img.shields.io/badge/License-Apache--2.0-green.svg)](https://github.com/xiaohaibin/XBanner/blob/master/LICENSE) 4 | 5 | ![1](https://github.com/xiaohaibin/XBanner/blob/master/sceenshots/xbanner.png) 6 | 7 | ## [English](https://github.com/xiaohaibin/XBanner/blob/master/README_EN.md) | 中文 8 | 9 | ## 主要功能: 10 | - 支持一屏显示多个 11 | - 支持自定义多布局,如:视频图片混合轮播 12 | - 支持根据服务端返回的数据动态设置广告条的总页数 13 | - 支持大于等于1页时的无限循环自动轮播、手指按下暂停轮播、抬起手指开始轮播 14 | - 支持自定义状态指示点位置 左 、中 、右 15 | - 支持自定义状态指示点 16 | - 支持监听页面点击事件 17 | - 支持设置图片轮播间隔 18 | - 支持指示器背景的修改及隐藏/显示 19 | - 支持显示提示性文字功能 20 | - 支持图片切换动画,目前支持10种切换动画,亦可设置自定义动画效果 21 | - 支持设置图片切换速度 22 | - 支持设置数字指示器 23 | - 支持设置图片框架整体占位图 24 | - 支持Glide/Fresco等主流图片加载框架加载图片 25 | - 支持自定义布局 26 | - 支持AndroidX 27 | ## 效果图 28 | 29 | |模式|效果图 30 | | :-: | :-: | 31 | |指示器模式|![效果示例](https://github.com/xiaohaibin/XBanner/blob/master/sceenshots/screenshot3.png)| 32 | |数字模式|![效果示例](https://github.com/xiaohaibin/XBanner/blob/master/sceenshots/screenshot6.png)| 33 | |数字加标题模式|![效果示例](https://github.com/xiaohaibin/XBanner/blob/master/sceenshots/screenshot5.png)| 34 | |指示器加标题模式|![效果示例](https://github.com/xiaohaibin/XBanner/blob/master/sceenshots/screenshot1.png)| 35 | |标题模式|![效果示例](https://github.com/xiaohaibin/XBanner/blob/master/sceenshots/screenshot2.png)| 36 | |一屏多页模式|![效果示例](https://github.com/xiaohaibin/XBanner/blob/master/sceenshots/screenshot4.png)| 37 | |一屏多页叠加模式|![效果示例](https://github.com/xiaohaibin/XBanner/blob/master/sceenshots/overlap.png)| 38 | |一屏多页模式支持多种效果自定义|![效果示例](https://github.com/xiaohaibin/XBanner/blob/master/sceenshots/screenshot7.png)| 39 | ## Demo Apk 40 | 41 | ![demo](https://github.com/xiaohaibin/XBanner/blob/master/sceenshots/apk_code.png) 42 | 43 | 44 | ## 基本使用 45 | 46 | #### 1.添加 Gradle (以前是有的是Jecenter方式引入,由于国内被墙了,切换成JitPack方式引入,使用方式不变) 47 | 48 | ## Jitpack 49 | 50 | Add it in your root build.gradle at the end of repositories: 51 | ``` 52 | allprojects { 53 | repositories { 54 | ... 55 | maven { url 'https://jitpack.io' } 56 | } 57 | } 58 | 59 | ``` 60 | Step 2. Add the dependency 61 | 62 | [![Version](https://jitpack.io/v/xiaohaibin/XBanner.svg)](https://jitpack.io/#xiaohaibin/XBanner) 63 | 64 | ``` 65 | dependencies { 66 | 67 | //普通版本依赖 68 | implementation 'com.github.xiaohaibin:XBanner:1.8.9' 69 | //androidX 版本使用下面的依赖 70 | implementation 'com.github.xiaohaibin:XBanner:androidx_v1.2.6' 71 | } 72 | ``` 73 | 74 | #### 2.在清单文件中添加网络权限 75 | 76 | ``` 77 | 78 | ``` 79 | 80 | #### 3.在布局文件中添加 XBanner 81 | > 注意:Androidx版本,包路径为:com.stx.xhb.androidx.XBanner 82 | ``` 83 | 97 | ``` 98 | 99 | 100 | #### 4.在 Activity 或者 Fragment 中配置 101 | 102 | > 初始化:直接传入视图集合进行初始化 103 | 104 | ``` 105 |        //获取控件 106 |        XBanner mXBanner = (XBanner) findViewById(R.id.xbanner); 107 | 108 | //代码设置框架占位图,也可在布局中设置 109 | mBanner.setBannerPlaceholderImg(R.mipmap.xbanner_logo, ImageView.ScaleType.CENTER_CROP); 110 | 111 | //添加轮播图片数据(图片数据不局限于网络图片、本地资源文件、View 都可以),刷新数据也是调用该方法 112 | mXBanner.setBannerData("轮播数据集合");//setData()方法已过时,推荐使用setBannerData()方法,具体参照demo使用 113 | 114 | ``` 115 | 116 | 117 | #### 5.图片加载 118 | 119 | > 可根据自己项目需要使用相应的图片加载工具进行**加载图片**,此处使用 Glide ,进行加载 120 | 121 | ``` 122 | //加载广告图片 123 | mXBanner.loadImage(new XBanner.XBannerAdapter() { 124 | @Override 125 | public void loadBanner(XBanner banner, Object model, View view, int position) { 126 | 127 | //1、此处使用的Glide加载图片,可自行替换自己项目中的图片加载框架 128 | //2、返回的图片路径为Object类型,你只需要强转成你传输的类型就行,切记不要胡乱强转! 129 | Glide.with(MainActivity.this).load(((AdvertiseEntity.OthersBean) 130 | model).getThumbnail()).placeholder(R.drawable.default_image).error(R.drawable.default_image).into((ImageView) view); 131 | } 132 | }); 133 | 134 | ``` 135 | 136 | #### 6.监听广告 item 的单击事件 137 | 138 | ``` 139 | mXBanner.setOnItemClickListener(new XBanner.OnItemClickListener() { 140 | @Override 141 | public void onItemClick(XBanner banner, Object model,View view, int position) { 142 | Toast.makeText(MainActivity.this, "点击了第"+position+"图片", Toast.LENGTH_SHORT).show(); 143 | } 144 | }); 145 | ``` 146 | 147 | #### 7.使用 Fresco 加载图片时,需要自定义布局文件 148 | 149 | 1.自定义布局文件 R.layout.image_fresco 150 | ``` 151 | 152 | 157 | ``` 158 | 2.使用 setBannerData() 方法进行设置 159 | ``` 160 | //setData()方法已过时,推荐使用setBannerData()方法,具体参照demo使用 161 | mXBanner.setBannerData(R.layout.image_fresco,“加载数据集合”); 162 | 163 | ``` 164 | 3. setBannerData 使用 165 | 166 | > setBannerData方法中的数据集合中的轮播实体类需要实现 BaseBannerInfo 接口,示例如下: 167 | 168 | ``` 169 |    public class CustomViewsInfo implements BaseBannerInfo { 170 | 171 | private String info; 172 | 173 | public CustomViewsInfo(String info) { 174 | this.info = info; 175 | } 176 | 177 | //轮播图片地址,本地图片就传本地资源的id,返回Int类型 178 | @Override 179 | public String getXBannerUrl() { 180 | return info; 181 | } 182 | 183 | //指示器文案 184 | @Override 185 | public String getXBannerTitle() { 186 | return "我是文案"; 187 | } 188 | } 189 | ``` 190 | #### 8.自定义布局 191 | 192 | 1.自定义自己需要展示的Banner显示布局,如:R.layout.customelayout 193 | 194 | ``` 195 | 196 | 205 | ``` 206 | 207 | 2.使用 setBannerData() 方法进行设置 208 | ``` 209 | mXBanner.setBannerData("自定义布局文件",“加载数据集合”); 210 | ``` 211 | 212 | 3.设置数据,通过 loadImage() 方法回传的 View 根据自定义布局设置的Id找到相应的控件进行数据设置,具体请看 [CustomViewsActivity](https://github.com/xiaohaibin/XBanner/blob/master/sample/src/main/java/com/stx/xhb/demo/CustomViewsActivity.java) 213 | ``` 214 | mBanner.loadImage(new XBanner.XBannerAdapter() { 215 | @Override 216 | public void loadBanner(XBanner banner, Object model, View view, int position) { 217 | TextView tvContent = (TextView) view.findViewById(R.id.tv); 218 | tvContent.setText(String.valueOf(position + 1)); 219 | view.setBackgroundColor(Color.parseColor((String) model)); 220 | } 221 | }); 222 | ``` 223 | 224 | #### 9.多布局使用(具体请看 [VideoViewActivity](https://github.com/xiaohaibin/XBanner/blob/master/sample/src/main/java/com/stx/xhb/demo/VideoViewActivity.java)) 225 | 226 | ``` 227 | //创建轮播item 的ViewHolder 228 | public class ImageViewHolder implements ViewHolder { 229 | 230 | @Override 231 | public int getLayoutId() { 232 | return R.layout.layout_image_view; 233 | } 234 | 235 | @Override 236 | public void onBind(View itemView, CustomViewsInfo data, int position) { 237 | ImageView imageView = itemView.findViewById(R.id.iv); 238 | Glide.with(itemView.getContext()).load(data.getXBannerUrl()).placeholder(R.drawable.default_image).error(R.drawable.default_image).into(imageView); 239 | } 240 | } 241 | ``` 242 | 243 | ``` 244 | //创建 HolderCreator 在里面根据viewType实现多布局的逻辑 245 | public class BannerHolderCreator implements HolderCreator { 246 | 247 | @Override 248 | public ViewHolder createViewHolder(int viewType) { 249 | if (viewType==0){ 250 | return new VideoViewHolder(); 251 | } 252 | return new ImageViewHolder(); 253 | } 254 | 255 | @Override 256 | public int getViewType(int position) { 257 | return position; 258 | } 259 | } 260 | ``` 261 | 262 | ``` 263 | //传 HolderCreator 264 | banner.setBannerData(“加载数据集合”, new BannerHolderCreator()); 265 | ``` 266 | 267 | 268 | ## 自定义属性说明 269 | 270 | | 属性名 | 属性说明 | 属性值 | 271 | | ------------ | ------------- | ------------ | 272 | | isAutoPlay| 是否支持自动轮播 | boolean类型,默认为true | 273 | | isTipsMarquee| 是否支持提示性文字跑马灯效果 | boolean类型,默认为false| 274 | | AutoPlayTime| 图片轮播时间间隔 | int值,默认为5s | 275 | | pointNormal| 指示器未选中时状态点 | drawable,不设置的话为默认状态点 | 276 | | pointSelect| 指示器选中时状态点 | drawable,不设置的话为默认状态点 | 277 | | pointsVisibility| 是否显示指示器 | boolean类型,默认为true | 278 | | pointsPosition| 指示器显示位置 | LEFT、CENTER、RIGHT类型,默认为CENTER | 279 | | pointsContainerBackground| 指示器背景 | 可自定义设置指示器背景 | 280 | | pointContainerPosition| 指示器容器显示位置 | TOP、BOTTOM类型,默认为BOTTOM | 281 | | pointContainerLeftRightPadding| 指示点容器左右内间距 | dimension,默认为10dp | 282 | | pointTopBottomPadding| 指示点上下内间距 | dimension,默认为6dp | 283 | | pointLeftRightPadding| 指示点左右内间距 | dimension,默认为3dp | 284 | | tipTextColor| 提示文案的文字颜色 | reference|color,默认为white | 285 | | tipTextSize| 提示文案的文字大小| dimension,默认为10dp | 286 | | isShowNumberIndicator| 是否显示数字指示器| boolean,默认为false不显示 | 287 | | numberIndicatorBacgroud|数字指示器背景| reference | 288 | | isShowIndicatorOnlyOne|当只有一张图片的时候是否显示指示点| boolean,默认为false,不显示 | 289 | | isShowTips|是否展示文字| boolean,默认为false,不显示 | 290 | | pageChangeDuration|图片切换速度| int值,默认为1000ms | 291 | | isHandLoop|是否支持手动无限循环切换图片| boolean类型,默认为false | 292 | | placeholderDrawable|设置整体轮播框架占位图| reference | 293 | | isClipChildrenMode|是否开启一屏显示多个模式| boolean类型,默认为false 默认不开启 | 294 | | clipChildrenLeftMargin|一屏显示多个左间距| dimension ,默认为30dp| 295 | | clipChildrenRightMargin|一屏显示多个右间距| dimension ,默认为30dp| 296 | | clipChildrenTopBottomMargin|一屏显示多个上下间距| dimension ,默认为30dp| 297 | | viewpagerMargin|viewpager页面间距| dimension ,默认为10dp| 298 | | isClipChildrenModeLessThree|少于三张是否支持一屏多显模式| boolean类型,默认为false 默认不开启 | 299 | | bannerBottomMargin|banner轮播区域底部margin,可设置指示器距离轮播图的间距| dimension ,默认为0dp| 300 | | scaleType|设置占位图缩放类型 |scaleType类型| 301 | | showIndicatorInCenter|设一屏多显模式下 指示器是否显示在中间图片位置,默认显示中间 |boolean类型| 302 | | isClickSide|一屏多显模式下 是否支持点击侧边切换图片,默认开启 |boolean类型| 303 | 304 | ## 混淆配置 305 | 306 | ``` 307 | ##XBanner 图片轮播混淆配置 308 | -keep class com.stx.xhb.xbanner.**{*;} 309 | ``` 310 | 311 | ## Q&A 312 | 313 | - 1.一屏显示多个模式默认使用ScalePageTransformer切换动画,也可以自定义;自定义动画添加方法setCustomPageTransformer(自定义动画效果); 314 | 315 | - 2.一屏显示多个模式默认是会缩放左右两个页面,若想左右页面与中间页面保持一致,把切换动画设置成自己自定义的就可以; 316 | 317 | - 3.图片不显示问题 318 | 319 | >1)确认是否实现了 **loadImage()** 方法,需要使用自己的图片加载框架加载图片!!! 320 | >2)请把加载图片地址复制到浏览器看看是否打开图片,确认图片地址是否正确!!! 321 | 322 | - 4.AndroidX模式配置问题 323 | https://blog.csdn.net/qq_17766199/article/details/81433706 324 | 325 | - 5.一屏显示多个模式开启没效果,请确认图片资源是否少于三张,如果少于三张依然需要一屏多显模式可通过 isClipChildrenModeLessThree 属性设置,该属性默认为false; 326 | 327 | ## 关于我 328 | 329 | * **Email**: 330 | * **Home**: 331 | * **掘金**: 332 | * **简书**: 333 | 334 | ## Thanks 335 | 336 | [bingoogolapple](https://github.com/bingoogolapple) 337 | 338 | 感谢[tanweijiu](https://github.com/tanweijiu)修复版本 1.1.2 中bug 339 | 340 | 感谢[Leoand8](https://github.com/Leoand8)修复版本 1.6.1 中bug 341 | 342 | 也欢迎各位感兴趣的开发者共同维护该项目。 343 | 344 | ### Contract 345 | 346 | [QQ群:271127803](http://qm.qq.com/cgi-bin/qm/qr?k=cM-ytK5bbZZZ4v7S1fMrTDzkjlFT0C9K) 347 | 348 | ![欢迎关注“大话微信”公众号](http://upload-images.jianshu.io/upload_images/1956769-2f49dcb0dc5195b6.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/400) 349 | 350 | 351 | ### 你的 Statr 是我最大的动力,谢谢~~~ 352 | 353 | 354 | License 355 | -- 356 | Copyright (C) 2016 xhb_199409@163.com 357 | 358 | Licensed under the Apache License, Version 2.0 (the "License"); 359 | you may not use this file except in compliance with the License. 360 | You may obtain a copy of the License at 361 | 362 | http://www.apache.org/licenses/LICENSE-2.0 363 | 364 | Unless required by applicable law or agreed to in writing, software 365 | distributed under the License is distributed on an "AS IS" BASIS, 366 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 367 | See the License for the specific language governing permissions and 368 | limitations under the License. 369 | -------------------------------------------------------------------------------- /README_EN.md: -------------------------------------------------------------------------------- 1 | ## XBanner 2 | 3 | [![License](https://img.shields.io/badge/License-Apache--2.0-green.svg)](https://github.com/xiaohaibin/XBanner/blob/master/LICENSE) 4 | 5 | ![1](https://github.com/xiaohaibin/XBanner/blob/master/sceenshots/xbanner.png) 6 | 7 | ## English | [中文](https://github.com/xiaohaibin/XBanner/blob/master/README.md) 8 | 9 | ## Functions: 10 | - Support multiple display on one screen 11 | - Support dynamic setting data 12 | - Support loop auto play 13 | - Support set indicator position left, center, right 14 | - Support custom indicator 15 | - Support Page OnClickListener 16 | - Support setting the playback interval 17 | - Support tip text 18 | - Support picture switching animation or customize 19 | - Support setting picture switching speed 20 | - Support setting digital indicator 21 | - Support setting imageplaceholder 22 | - Support Glide/Fresco 23 | - Support Custom layout 24 | - Support AndroidX 25 | 26 | ## Styles 27 | 28 | |mode|picture 29 | | :-: | :-: | 30 | |normal indicator|![效果示例](https://github.com/xiaohaibin/XBanner/blob/master/sceenshots/screenshot3.png)| 31 | |number indicator|![效果示例](https://github.com/xiaohaibin/XBanner/blob/master/sceenshots/screenshot6.png)| 32 | |number indicator and title|![效果示例](https://github.com/xiaohaibin/XBanner/blob/master/sceenshots/screenshot5.png)| 33 | |normal indicator and title|![效果示例](https://github.com/xiaohaibin/XBanner/blob/master/sceenshots/screenshot1.png)| 34 | |title|![效果示例](https://github.com/xiaohaibin/XBanner/blob/master/sceenshots/screenshot2.png)| 35 | |multiple page|![效果示例](https://github.com/xiaohaibin/XBanner/blob/master/sceenshots/screenshot4.png)| 36 | |multiple page|![效果示例](https://github.com/xiaohaibin/XBanner/blob/master/sceenshots/screenshot7.png)| 37 | |overlap|![效果示例](https://github.com/xiaohaibin/XBanner/blob/master/sceenshots/overlap.png)| 38 | 39 | ## Demo Apk 40 | 41 | ![demo](https://github.com/xiaohaibin/XBanner/blob/master/sceenshots/apk_code.png) 42 | 43 | 44 | ## Usage 45 | 46 | #### 1.Add Gradle 47 | 48 | #### Jitpack 49 | 50 | Add it in your root build.gradle at the end of repositories: 51 | ``` 52 | allprojects { 53 | repositories { 54 | ... 55 | maven { url 'https://jitpack.io' } 56 | } 57 | } 58 | 59 | ``` 60 | Step 2. Add the dependency 61 | 62 | [![Version](https://jitpack.io/v/xiaohaibin/XBanner.svg)](https://jitpack.io/#xiaohaibin/XBanner) 63 | 64 | ``` 65 | dependencies { 66 | 67 | //Normal 68 | implementation 'com.github.xiaohaibin:XBanner:1.8.6' 69 | 70 | //androidX 71 | implementation 'com.github.xiaohaibin:XBanner:androidx_v1.2.3' 72 | } 73 | ``` 74 | 75 | #### 2.Add network permissions to the manifest file 76 | 77 | ``` 78 | 79 | ``` 80 | 81 | #### 3.Add XBanner in the layout file 82 | ``` 83 | 97 | ``` 98 | 99 | 100 | #### 4.Use in Activity or Fragment 101 | 102 | > initialization:set banner data 103 | 104 | ``` 105 | //get xbanner 106 | XBanner mXBanner = (XBanner) findViewById(R.id.xbanner); 107 | 108 | //setBannerPlaceholderImg 109 | mBanner.setBannerPlaceholderImg(R.mipmap.xbanner_logo, ImageView.ScaleType.CENTER_CROP); 110 | 111 | //add data(network data、local file、View),refresh data also use this method 112 | mXBanner.setBannerData("data"); 113 | 114 | ``` 115 | 116 | 117 | #### 5.load image 118 | 119 | > according your project choose imageload framework,this use Glide load image 120 | 121 | ``` 122 | //load image 123 | mXBanner.loadImage(new XBanner.XBannerAdapter() { 124 | @Override 125 | public void loadBanner(XBanner banner, Object model, View view, int position) { 126 | 127 | Glide.with(MainActivity.this).load(((AdvertiseEntity.OthersBean) 128 | model).getThumbnail()).placeholder(R.drawable.default_image).error(R.drawable.default_image).into((ImageView) view); 129 | } 130 | }); 131 | 132 | ``` 133 | 134 | #### 6.setOnItemClickListener 135 | 136 | ``` 137 | mXBanner.setOnItemClickListener(new XBanner.OnItemClickListener() { 138 | @Override 139 | public void onItemClick(XBanner banner, Object model,View view, int position) { 140 | Toast.makeText(MainActivity.this, "点击了第"+position+"图片", Toast.LENGTH_SHORT).show(); 141 | } 142 | }); 143 | ``` 144 | 145 | #### 7.Use Fresco load image 146 | 147 | 1.custom layout R.layout.image_fresco 148 | ``` 149 | 150 | 155 | ``` 156 | 2.use setBannerData() method 157 | ``` 158 | mXBanner.setBannerData(R.layout.image_fresco,“banner data”); 159 | 160 | ``` 161 | 3.setBannerData 162 | 163 | > Before you use setBannerData,you should let banner eneity implement the interface,eg: 164 | 165 | ``` 166 |    public class CustomViewsInfo implements BaseBannerInfo { 167 | 168 | private String info; 169 | 170 | public CustomViewsInfo(String info) { 171 | this.info = info; 172 | } 173 | 174 | //image url 175 | @Override 176 | public String getXBannerUrl() { 177 | return info; 178 | } 179 | 180 | //tips 181 | @Override 182 | public String getXBannerTitle() { 183 | return "tips"; 184 | } 185 | } 186 | ``` 187 | #### 8.Custom layout 188 | 189 | 1.Custom layout,eg:R.layout.customelayout 190 | 191 | ``` 192 | 193 | 202 | ``` 203 | 204 | 2.Use setBannerData() method 205 | ``` 206 | mXBanner.setBannerData("custom latout",“data”); 207 | ``` 208 | 209 | 3.loadimage,see [CustomViewsActivity](https://github.com/xiaohaibin/XBanner/blob/master/sample/src/main/java/com/stx/xhb/demo/CustomViewsActivity.java) 210 | ``` 211 | mBanner.loadImage(new XBanner.XBannerAdapter() { 212 | @Override 213 | public void loadBanner(XBanner banner, Object model, View view, int position) { 214 | TextView tvContent = (TextView) view.findViewById(R.id.tv); 215 | tvContent.setText(String.valueOf(position + 1)); 216 | view.setBackgroundColor(Color.parseColor((String) model)); 217 | } 218 | }); 219 | ``` 220 | 221 | ## Attributes in xml 222 | 223 | | Attributes | description | format | 224 | | ------------ | ------------- | ------------ | 225 | | isAutoPlay| set isAutoPlay | boolean,default true | 226 | | isTipsMarquee| set isTipsMarquee | boolean,default false| 227 | | AutoPlayTime| set AutoPlayTime | integer,default 5s | 228 | | pointNormal| set indicator pointNormal | drawable| 229 | | pointSelect| set indicator pointSelect | drawable | 230 | | pointsVisibility| set indicator isVisible | boolean,default true | 231 | | pointsPosition| set indicator postion | LEFT、CENTER、RIGHT,default CENTER | 232 | | pointsContainerBackground| set indicator baground | drawable | 233 | | pointContainerPosition| set pointContainerPosition | TOP、BOTTOM,default BOTTOM | 234 | | pointContainerLeftRightPadding| set pointContainerLeftRightPadding | dimension,default 10dp | 235 | | pointTopBottomPadding| set pointTopBottomPadding | dimension,default 6dp | 236 | | pointLeftRightPadding| set pointLeftRightPadding | dimension,default 3dp | 237 | | tipTextColor| 提示文案的文字颜色 | reference|color,default white | 238 | | tipTextSize| 提示文案的文字大小| dimension,default 10dp | 239 | | isShowNumberIndicator| 是否显示数字指示器| boolean,default false | 240 | | numberIndicatorBacgroud|数字指示器背景| reference | 241 | | isShowIndicatorOnlyOne|当只有一张图片的时候是否显示指示点| boolean,default false | 242 | | isShowTips|是否展示文字| boolean,default false | 243 | | pageChangeDuration|图片切换速度| integer,default 1000ms | 244 | | isHandLoop|是否支持手动无限循环切换图片| boolean,default false | 245 | | placeholderDrawable|设置整体轮播框架占位图| reference | 246 | | isClipChildrenMode|是否开启一屏显示多个模式| boolean,default false | 247 | | clipChildrenLeftMargin|一屏显示多个左间距| dimension ,default 30dp| 248 | | clipChildrenRightMargin|一屏显示多个右间距| dimension ,default 30dp| 249 | | clipChildrenTopBottomMargin|一屏显示多个上下间距| dimension ,default 30dp| 250 | | viewpagerMargin|viewpager页面间距| dimension ,default 10dp| 251 | | isClipChildrenModeLessThree|少于三张是否支持一屏多显模式| boolean,default false | 252 | | bannerBottomMargin|banner轮播区域底部margin,可设置指示器距离轮播图的间距| dimension ,default 0dp| 253 | | scaleType|设置占位图缩放类型 |scaleType类型| 254 | | showIndicatorInCenter|设一屏多显模式下 指示器是否显示在中间图片位置,默认显示中间 |boolean| 255 | | isClickSide|一屏多显模式下 是否支持点击侧边切换图片,默认开启 |boolean| 256 | 257 | ## Progard 258 | 259 | ``` 260 | ##XBanner Progard 261 | -keep class com.stx.xhb.xbanner.**{*;} 262 | ``` 263 | 264 | ## About 265 | 266 | * **Email**: 267 | * **Home**: 268 | * **掘金**: 269 | * **简书**: 270 | 271 | ## Thanks 272 | 273 | [bingoogolapple](https://github.com/bingoogolapple) 274 | 275 | Thanks[tanweijiu](https://github.com/tanweijiu)fix 1.1.2 中bug 276 | 277 | Thanks[Leoand8](https://github.com/Leoand8)fix 1.6.1 中bug 278 | 279 | 280 | ### Your Star is my biggest motivation,Thanks~~~ 281 | 282 | 283 | License 284 | -- 285 | Copyright (C) 2016 xhb_199409@163.com 286 | 287 | Licensed under the Apache License, Version 2.0 (the "License"); 288 | you may not use this file except in compliance with the License. 289 | You may obtain a copy of the License at 290 | 291 | http://www.apache.org/licenses/LICENSE-2.0 292 | 293 | Unless required by applicable law or agreed to in writing, software 294 | distributed under the License is distributed on an "AS IS" BASIS, 295 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 296 | See the License for the specific language governing permissions and 297 | limitations under the License. 298 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | google() 7 | } 8 | dependencies { 9 | classpath 'com.android.tools.build:gradle:3.2.1' 10 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4' 11 | classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' 12 | // NOTE: Do not place your application dependencies here; they belong 13 | // in the individual module build.gradle files 14 | } 15 | } 16 | 17 | allprojects { 18 | repositories { 19 | jcenter() 20 | google() 21 | maven { url 'https://jitpack.io' } 22 | } 23 | } 24 | 25 | task clean(type: Delete) { 26 | delete rootProject.buildDir 27 | } 28 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | org.gradle.jvmargs=-Xmx512m 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true 19 | android.useAndroidX=false 20 | android.enableJetifier=false -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Oct 05 10:43:20 CST 2021 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.8.1-all.zip 7 | -------------------------------------------------------------------------------- /sample/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | /.idea -------------------------------------------------------------------------------- /sample/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 28 5 | buildToolsVersion '28.0.3' 6 | defaultConfig { 7 | applicationId "com.stx.xhb.xbanner" 8 | minSdkVersion 16 9 | targetSdkVersion 28 10 | versionCode 1 11 | versionName "1.0" 12 | packagingOptions { 13 | exclude 'META-INF/proguard/androidx-annotations.pro' 14 | } 15 | } 16 | buildTypes { 17 | release { 18 | minifyEnabled false 19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 20 | } 21 | } 22 | } 23 | 24 | dependencies { 25 | implementation fileTree(include: ['*.jar'], dir: 'libs') 26 | implementation 'com.android.support:appcompat-v7:28.0.0' 27 | implementation 'com.github.bumptech.glide:glide:3.8.0' 28 | implementation 'com.zhy:okhttputils:2.6.2' 29 | implementation project(':xbanner') 30 | // implementation 'com.github.xiaohaibin:XBanner:1.8.9' 31 | implementation 'com.facebook.fresco:fresco:1.10.0' 32 | implementation 'me.relex:circleindicator:2.1.0' 33 | implementation 'com.google.code.gson:gson:2.8.5' 34 | implementation 'com.android.support:cardview-v7:28.0.0' 35 | implementation "com.android.support:recyclerview-v7:28+" 36 | implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.50' 37 | implementation 'com.blankj:utilcode:1.23.7' 38 | implementation 'com.android.support:support-v4:28.0.0' 39 | implementation 'com.android.support:swiperefreshlayout:28.0.0' 40 | implementation 'org.jetbrains:annotations-java5:15.0' 41 | 42 | implementation 'xyz.doikki.android.dkplayer:dkplayer-java:3.3.5' 43 | implementation 'xyz.doikki.android.dkplayer:player-ijk:3.3.5' 44 | implementation 'xyz.doikki.android.dkplayer:videocache:3.3.5' 45 | implementation 'xyz.doikki.android.dkplayer:dkplayer-ui:3.3.5' 46 | 47 | } 48 | -------------------------------------------------------------------------------- /sample/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\Android\AndroidSDK/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /sample/sample.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 10 | 11 | 12 | 13 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | -------------------------------------------------------------------------------- /sample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 17 | 20 | 24 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 36 | 39 | 42 | 45 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /sample/src/main/java/com/stx/xhb/demo/ClipChildrenModeActivity.java: -------------------------------------------------------------------------------- 1 | package com.stx.xhb.demo; 2 | 3 | import android.net.Uri; 4 | import android.os.Bundle; 5 | import android.support.v4.view.ViewPager; 6 | import android.support.v7.app.AppCompatActivity; 7 | import android.util.Log; 8 | import android.view.View; 9 | import android.widget.LinearLayout; 10 | import android.widget.Toast; 11 | 12 | import com.blankj.utilcode.util.ToastUtils; 13 | import com.facebook.drawee.view.SimpleDraweeView; 14 | import com.google.gson.Gson; 15 | import com.stx.xhb.xbanner.XBanner; 16 | import com.stx.xhb.xbanner.entity.LocalImageInfo; 17 | import com.stx.xhb.xbanner.transformers.Transformer; 18 | import com.stx.xhb.demo.entity.TuchongEntity; 19 | import com.zhy.http.okhttp.OkHttpUtils; 20 | import com.zhy.http.okhttp.callback.StringCallback; 21 | 22 | import java.util.ArrayList; 23 | import java.util.List; 24 | 25 | import okhttp3.Call; 26 | 27 | /** 28 | * 一屏显示多个,类似魅族Banner模式 29 | */ 30 | public class ClipChildrenModeActivity extends AppCompatActivity { 31 | 32 | private XBanner mBanner; 33 | private XBanner mBanner2; 34 | private XBanner mBanner3; 35 | private XBanner mBanner4; 36 | private XBanner mBanner5; 37 | 38 | @Override 39 | protected void onCreate(Bundle savedInstanceState) { 40 | super.onCreate(savedInstanceState); 41 | setContentView(R.layout.activity_clip_children_mode); 42 | mBanner = findViewById(R.id.banner); 43 | mBanner2 = findViewById(R.id.banner2); 44 | mBanner3 = findViewById(R.id.banner3); 45 | mBanner4 = findViewById(R.id.banner4); 46 | mBanner5 = findViewById(R.id.banner5); 47 | 48 | LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, ScreenUtil.getScreenWidth(this) / 2); 49 | 50 | mBanner.setLayoutParams(layoutParams); 51 | 52 | mBanner2.setLayoutParams(layoutParams); 53 | 54 | mBanner3.setLayoutParams(layoutParams); 55 | 56 | mBanner4.setLayoutParams(layoutParams); 57 | 58 | mBanner5.setLayoutParams(layoutParams); 59 | 60 | initBanner(mBanner); 61 | initBanner(mBanner2); 62 | initBanner(mBanner3); 63 | initBanner(mBanner4); 64 | initBanner(mBanner5); 65 | 66 | initData(); 67 | // initLocalImage(); 68 | } 69 | 70 | 71 | /** 72 | * 初始化XBanner 73 | */ 74 | private void initBanner(XBanner banner) { 75 | //设置广告图片点击事件 76 | banner.setOnItemClickListener(new XBanner.OnItemClickListener() { 77 | @Override 78 | public void onItemClick(XBanner banner, Object model, View view, int position) { 79 | ToastUtils.showShort(getString(R.string.string_click) + (position + 1) + "图片"); 80 | } 81 | }); 82 | //加载广告图片 83 | banner.loadImage(new XBanner.XBannerAdapter() { 84 | @Override 85 | public void loadBanner(XBanner banner, Object model, View view, int position) { 86 | //此处适用Fresco加载网络图片,可自行替换自己的图片加载框架 87 | SimpleDraweeView draweeView = (SimpleDraweeView) view; 88 | TuchongEntity.FeedListBean.EntryBean listBean = ((TuchongEntity.FeedListBean.EntryBean) model); 89 | String url = "https://photo.tuchong.com/" + listBean.getImages().get(0).getUser_id() + "/f/" + listBean.getImages().get(0).getImg_id() + ".jpg"; 90 | draweeView.setImageURI(Uri.parse(url)); 91 | // 加载本地图片展示 92 | // ((ImageView)view).setImageResource(((LocalImageInfo) model).getXBannerUrl()); 93 | } 94 | }); 95 | banner.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { 96 | @Override 97 | public void onPageScrolled(int i, float v, int i1) { 98 | } 99 | 100 | @Override 101 | public void onPageSelected(int i) { 102 | Log.i("onPageSelected===>", i + ""); 103 | } 104 | 105 | @Override 106 | public void onPageScrollStateChanged(int i) { 107 | 108 | } 109 | }); 110 | } 111 | 112 | /** 113 | * 初始化数据 114 | */ 115 | private void initData() { 116 | //加载网络图片资源 117 | String url = "https://api.tuchong.com/2/wall-paper/app"; 118 | OkHttpUtils 119 | .get() 120 | .url(url) 121 | .build() 122 | .execute(new StringCallback() { 123 | @Override 124 | public void onError(Call call, Exception e, int id) { 125 | Toast.makeText(ClipChildrenModeActivity.this, "加载广告数据失败", Toast.LENGTH_SHORT).show(); 126 | } 127 | 128 | @Override 129 | public void onResponse(String response, int id) { 130 | TuchongEntity advertiseEntity = new Gson().fromJson(response, TuchongEntity.class); 131 | List others = advertiseEntity.getFeedList(); 132 | List data = new ArrayList<>(); 133 | for (int i = 0; i < others.size(); i++) { 134 | TuchongEntity.FeedListBean feedListBean = others.get(i); 135 | if ("post".equals(feedListBean.getType())) { 136 | data.add(feedListBean.getEntry()); 137 | } 138 | } 139 | 140 | //刷新数据之后,需要重新设置是否支持自动轮播 141 | mBanner.setAutoPlayAble(data.size() > 1); 142 | mBanner.setIsClipChildrenMode(true); 143 | mBanner.setOverlapStyle(true); 144 | mBanner.setBannerData(R.layout.layout_fresco_imageview, data); 145 | 146 | //刷新数据之后,需要重新设置是否支持自动轮播 147 | mBanner2.setAutoPlayAble(data.size() > 1); 148 | mBanner2.setIsClipChildrenMode(true); 149 | mBanner2.setBannerData(R.layout.layout_fresco_imageview, data); 150 | mBanner2.getViewPager().setOffscreenPageLimit(4); 151 | 152 | //刷新数据之后,需要重新设置是否支持自动轮播 153 | mBanner3.setAutoPlayAble(data.size() > 1); 154 | mBanner3.setIsClipChildrenMode(true); 155 | mBanner3.setBannerData(R.layout.layout_fresco_imageview, data); 156 | mBanner3.setPageTransformer(Transformer.Default); 157 | mBanner3.getViewPager().setOffscreenPageLimit(3); 158 | 159 | //刷新数据之后,需要重新设置是否支持自动轮播 160 | mBanner4.setAutoPlayAble(data.size() > 1); 161 | mBanner4.setIsClipChildrenMode(true); 162 | mBanner4.setBannerData(R.layout.layout_fresco_imageview, data); 163 | 164 | //刷新数据之后,需要重新设置是否支持自动轮播 165 | mBanner5.setAutoPlayAble(data.size() > 1); 166 | mBanner5.setIsClipChildrenMode(true); 167 | mBanner5.setBannerData(R.layout.layout_fresco_imageview, data); 168 | mBanner5.setPageTransformer(Transformer.Scale); 169 | } 170 | }); 171 | } 172 | 173 | /** 174 | * 加载本地图片 175 | */ 176 | private void initLocalImage() { 177 | List data = new ArrayList<>(); 178 | data.add(new LocalImageInfo(R.drawable.banner_placeholder)); 179 | data.add(new LocalImageInfo(R.drawable.banner_placeholder)); 180 | data.add(new LocalImageInfo(R.drawable.banner_placeholder)); 181 | data.add(new LocalImageInfo(R.drawable.banner_placeholder)); 182 | mBanner.setBannerData(data); 183 | mBanner.setAutoPlayAble(true); 184 | } 185 | } 186 | -------------------------------------------------------------------------------- /sample/src/main/java/com/stx/xhb/demo/CustomViewsActivity.java: -------------------------------------------------------------------------------- 1 | package com.stx.xhb.demo; 2 | 3 | import android.graphics.Color; 4 | import android.os.Bundle; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.view.View; 7 | import android.widget.TextView; 8 | import android.widget.Toast; 9 | 10 | import com.blankj.utilcode.util.ToastUtils; 11 | import com.stx.xhb.xbanner.XBanner; 12 | import com.stx.xhb.demo.entity.CustomViewsInfo; 13 | 14 | import java.util.ArrayList; 15 | import java.util.List; 16 | 17 | 18 | /** 19 | * 自定义布局 20 | */ 21 | public class CustomViewsActivity extends AppCompatActivity { 22 | 23 | @Override 24 | protected void onCreate(Bundle savedInstanceState) { 25 | super.onCreate(savedInstanceState); 26 | setContentView(R.layout.activity_custom_views); 27 | initView(); 28 | } 29 | 30 | private void initView() { 31 | XBanner banner = (XBanner) findViewById(R.id.banner); 32 | List data = new ArrayList<>(); 33 | data.add(new CustomViewsInfo("#FFA54F")); 34 | data.add(new CustomViewsInfo("#8EE5EE")); 35 | data.add(new CustomViewsInfo("#00FA9A")); 36 | data.add(new CustomViewsInfo("#CD8162")); 37 | banner.setBannerData(R.layout.layout_custom_view, data); 38 | banner.loadImage(new XBanner.XBannerAdapter() { 39 | @Override 40 | public void loadBanner(XBanner banner, Object model, View view, int position) { 41 | TextView tvContent = (TextView) view.findViewById(R.id.tv); 42 | tvContent.setText(String.valueOf(position + 1)); 43 | view.setBackgroundColor(Color.parseColor(((CustomViewsInfo) model).getXBannerUrl())); 44 | } 45 | }); 46 | banner.setOnItemClickListener(new XBanner.OnItemClickListener() { 47 | @Override 48 | public void onItemClick(XBanner banner, Object model, View view, int position) { 49 | ToastUtils.showShort("点击了" + position); 50 | } 51 | }); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /sample/src/main/java/com/stx/xhb/demo/GuideActivity.java: -------------------------------------------------------------------------------- 1 | package com.stx.xhb.demo; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.support.v4.view.ViewPager; 6 | import android.support.v7.app.AppCompatActivity; 7 | import android.view.View; 8 | import android.view.WindowManager; 9 | import android.widget.Button; 10 | import android.widget.ImageView; 11 | 12 | 13 | import com.stx.xhb.xbanner.XBanner; 14 | import com.stx.xhb.xbanner.entity.LocalImageInfo; 15 | 16 | import java.util.ArrayList; 17 | import java.util.List; 18 | 19 | /** 20 | * XBanner 使用在引导页控件 21 | */ 22 | public class GuideActivity extends AppCompatActivity { 23 | 24 | private XBanner mXBanner; 25 | private Button mBtnEnter; 26 | 27 | @Override 28 | protected void onCreate(Bundle savedInstanceState) { 29 | super.onCreate(savedInstanceState); 30 | setContentView(R.layout.activity_splash); 31 | getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 32 | initView(); 33 | } 34 | 35 | 36 | private void initView() { 37 | mXBanner = findViewById(R.id.xbanner); 38 | mBtnEnter = findViewById(R.id.btn); 39 | List localImageInfoList=new ArrayList<>(); 40 | localImageInfoList.add(new LocalImageInfo(R.mipmap.we1)); 41 | localImageInfoList.add(new LocalImageInfo(R.mipmap.we2)); 42 | localImageInfoList.add(new LocalImageInfo(R.mipmap.we3)); 43 | mXBanner.setBannerData(localImageInfoList); 44 | mXBanner.loadImage(new XBanner.XBannerAdapter() { 45 | @Override 46 | public void loadBanner(XBanner banner, Object model, View view, int position) { 47 | ((ImageView) view).setImageResource(((LocalImageInfo) model).getXBannerUrl()); 48 | } 49 | }); 50 | mXBanner.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { 51 | @Override 52 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { 53 | if (position == mXBanner.getRealCount() - 1) { 54 | mBtnEnter.setVisibility(View.VISIBLE); 55 | } else { 56 | mBtnEnter.setVisibility(View.GONE); 57 | } 58 | } 59 | }); 60 | mBtnEnter.setOnClickListener(new View.OnClickListener() { 61 | @Override 62 | public void onClick(View v) { 63 | startActivity(new Intent(GuideActivity.this, ListViewActivity.class)); 64 | finish(); 65 | } 66 | }); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /sample/src/main/java/com/stx/xhb/demo/ListViewActivity.java: -------------------------------------------------------------------------------- 1 | package com.stx.xhb.demo; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.widget.SwipeRefreshLayout; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.view.View; 7 | import android.widget.AdapterView; 8 | import android.widget.ArrayAdapter; 9 | import android.widget.ImageView; 10 | import android.widget.LinearLayout; 11 | import android.widget.Toast; 12 | 13 | import com.bumptech.glide.Glide; 14 | import com.google.gson.Gson; 15 | import com.stx.xhb.xbanner.XBanner; 16 | import com.stx.xhb.xbanner.transformers.Transformer; 17 | import com.stx.xhb.demo.entity.TuchongEntity; 18 | import com.zhy.http.okhttp.OkHttpUtils; 19 | import com.zhy.http.okhttp.callback.StringCallback; 20 | import java.util.ArrayList; 21 | import java.util.List; 22 | import okhttp3.Call; 23 | 24 | /** 25 | * listview 添加headview使用 RecycleView上也是同样的 26 | */ 27 | public class ListViewActivity extends AppCompatActivity { 28 | 29 | private XBanner mXBanner; 30 | private android.widget.ListView mLv; 31 | private SwipeRefreshLayout mRefreshLayout; 32 | 33 | @Override 34 | protected void onCreate(Bundle savedInstanceState) { 35 | super.onCreate(savedInstanceState); 36 | setContentView(R.layout.activity_listview); 37 | requsetData(); 38 | initView(); 39 | setAdapter(); 40 | setListener(); 41 | } 42 | 43 | 44 | /** 45 | * 设置适配器 46 | */ 47 | private void setAdapter() { 48 | ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, getResources().getStringArray(R.array.transforms)); 49 | mLv.setAdapter(adapter); 50 | mLv.setOnItemClickListener(new AdapterView.OnItemClickListener() { 51 | @Override 52 | public void onItemClick(AdapterView parent, View view, int position, long id) { 53 | switch (position) { 54 | //默认切换动画 55 | case 0: 56 | mXBanner.setPageTransformer(Transformer.Default); 57 | break; 58 | case 1: 59 | mXBanner.setPageTransformer(Transformer.Alpha); 60 | break; 61 | case 2: 62 | mXBanner.setPageTransformer(Transformer.Rotate); 63 | break; 64 | case 3: 65 | mXBanner.setPageTransformer(Transformer.Cube); 66 | break; 67 | case 4: 68 | mXBanner.setPageTransformer(Transformer.Flip); 69 | break; 70 | case 5: 71 | mXBanner.setPageTransformer(Transformer.Accordion); 72 | break; 73 | case 6: 74 | mXBanner.setPageTransformer(Transformer.ZoomFade); 75 | break; 76 | case 7: 77 | mXBanner.setPageTransformer(Transformer.ZoomCenter); 78 | break; 79 | case 8: 80 | mXBanner.setPageTransformer(Transformer.ZoomStack); 81 | break; 82 | case 9: 83 | mXBanner.setPageTransformer(Transformer.Stack); 84 | break; 85 | case 10: 86 | mXBanner.setPageTransformer(Transformer.Depth); 87 | break; 88 | case 11: 89 | mXBanner.setPageTransformer(Transformer.Zoom); 90 | break; 91 | default: 92 | mXBanner.setPageTransformer(Transformer.Default); 93 | break; 94 | } 95 | } 96 | }); 97 | } 98 | 99 | /** 100 | * 加载网络数据 101 | */ 102 | private void requsetData() { 103 | //加载网络图片资源 104 | String url = "https://api.tuchong.com/2/wall-paper/app"; 105 | OkHttpUtils 106 | .get() 107 | .url(url) 108 | .build() 109 | .execute(new StringCallback() { 110 | @Override 111 | public void onError(Call call, Exception e, int id) { 112 | Toast.makeText(ListViewActivity.this, "加载广告数据失败", Toast.LENGTH_SHORT).show(); 113 | } 114 | 115 | @Override 116 | public void onResponse(String response, int id) { 117 | TuchongEntity advertiseEntity = new Gson().fromJson(response, TuchongEntity.class); 118 | List others = advertiseEntity.getFeedList(); 119 | List data = new ArrayList<>(); 120 | for (int i = 0; i < others.size(); i++) { 121 | TuchongEntity.FeedListBean feedListBean = others.get(i); 122 | if ("post".equals(feedListBean.getType())) { 123 | data.add(feedListBean.getEntry()); 124 | } 125 | } 126 | //刷新数据之后,需要重新设置是否支持自动轮播 127 | mXBanner.setAutoPlayAble(data.size() > 1); 128 | mXBanner.setBannerData(data); 129 | } 130 | }); 131 | } 132 | 133 | /** 134 | * 初始化View 135 | */ 136 | private void initView() { 137 | mLv = findViewById(R.id.lv); 138 | mRefreshLayout = findViewById(R.id.refresh_layout); 139 | 140 | // 初始化HeaderView 141 | View headerView = View.inflate(this, R.layout.ad_head, null); 142 | mXBanner = headerView.findViewById(R.id.banner); 143 | mXBanner.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, ScreenUtil.getScreenWidth(this) / 2)); 144 | mLv.addHeaderView(headerView); 145 | 146 | mRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { 147 | @Override 148 | public void onRefresh() { 149 | requsetData(); 150 | mRefreshLayout.setRefreshing(false); 151 | } 152 | }); 153 | } 154 | 155 | /** 156 | * 初始化XBanner 157 | */ 158 | private void setListener() { 159 | //设置广告图片点击事件 160 | mXBanner.setOnItemClickListener(new XBanner.OnItemClickListener() { 161 | @Override 162 | public void onItemClick(XBanner banner, Object model, View view, int position) { 163 | Toast.makeText(ListViewActivity.this, "点击了第" + (position + 1) + "图片", Toast.LENGTH_SHORT).show(); 164 | } 165 | }); 166 | //加载广告图片 167 | mXBanner.loadImage(new XBanner.XBannerAdapter() { 168 | @Override 169 | public void loadBanner(XBanner banner, Object model, View view, int position) { 170 | //在此处使用图片加载框架加载图片,demo中使用glide加载,可替换成自己项目中的图片加载框架 171 | TuchongEntity.FeedListBean.EntryBean listBean = ((TuchongEntity.FeedListBean.EntryBean) model); 172 | String url = "https://photo.tuchong.com/" + listBean.getImages().get(0).getUser_id() + "/f/" + listBean.getImages().get(0).getImg_id() + ".jpg"; 173 | Glide.with(ListViewActivity.this).load(url).placeholder(R.drawable.default_image).error(R.drawable.default_image).into((ImageView) view); 174 | } 175 | }); 176 | } 177 | } 178 | -------------------------------------------------------------------------------- /sample/src/main/java/com/stx/xhb/demo/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.stx.xhb.demo; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.util.Log; 7 | import android.view.View; 8 | import android.widget.AdapterView; 9 | import android.widget.ArrayAdapter; 10 | import android.widget.ImageView; 11 | import android.widget.LinearLayout; 12 | import android.widget.ListView; 13 | import android.widget.Toast; 14 | 15 | 16 | import com.blankj.utilcode.util.LogUtils; 17 | import com.blankj.utilcode.util.ToastUtils; 18 | import com.bumptech.glide.Glide; 19 | import com.google.gson.Gson; 20 | import com.stx.xhb.demo.entity.TuchongEntity; 21 | import com.stx.xhb.xbanner.XBanner; 22 | import com.zhy.http.okhttp.OkHttpUtils; 23 | import com.zhy.http.okhttp.callback.StringCallback; 24 | 25 | import java.util.ArrayList; 26 | import java.util.List; 27 | 28 | import okhttp3.Call; 29 | 30 | public class MainActivity extends AppCompatActivity implements View.OnClickListener { 31 | 32 | private XBanner mBanner; 33 | List tempData = new ArrayList<>(); 34 | 35 | @Override 36 | protected void onCreate(Bundle savedInstanceState) { 37 | super.onCreate(savedInstanceState); 38 | setContentView(R.layout.activity_main); 39 | findViewById(R.id.btn).setOnClickListener(this); 40 | initView(); 41 | initBanner(); 42 | initData(); 43 | } 44 | 45 | private void initView() { 46 | mBanner = (XBanner) findViewById(R.id.banner); 47 | mBanner.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, ScreenUtil.getScreenWidth(this) / 2)); 48 | ListView listView = (ListView) findViewById(R.id.lv); 49 | ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, getResources().getStringArray(R.array.pages)); 50 | listView.setAdapter(adapter); 51 | listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { 52 | @Override 53 | public void onItemClick(AdapterView parent, View view, int position, long id) { 54 | switch (position) { 55 | case 0: 56 | startActivity(new Intent(MainActivity.this, ListViewActivity.class)); 57 | break; 58 | case 1: 59 | startActivity(new Intent(MainActivity.this, GuideActivity.class)); 60 | break; 61 | case 2: 62 | startActivity(new Intent(MainActivity.this, CustomViewsActivity.class)); 63 | break; 64 | case 3: 65 | startActivity(new Intent(MainActivity.this, ClipChildrenModeActivity.class)); 66 | break; 67 | case 4: 68 | startActivity(new Intent(MainActivity.this, RecyclerViewActivity.class)); 69 | break; 70 | case 5: 71 | startActivity(new Intent(MainActivity.this, UserInFragmentActivity.class)); 72 | break; 73 | case 6: 74 | startActivity(new Intent(MainActivity.this, VideoViewActivity.class)); 75 | break; 76 | default: 77 | break; 78 | } 79 | } 80 | }); 81 | } 82 | 83 | /** 84 | * 初始化XBanner 85 | */ 86 | private void initBanner() { 87 | //设置广告图片点击事件 88 | mBanner.setOnItemClickListener(new XBanner.OnItemClickListener() { 89 | @Override 90 | public void onItemClick(XBanner banner, Object model, View view, int position) { 91 | ToastUtils.showShort("点击了第" + (position + 1) + "图片"); 92 | } 93 | }); 94 | //加载广告图片 95 | mBanner.loadImage(new XBanner.XBannerAdapter() { 96 | @Override 97 | public void loadBanner(XBanner banner, Object model, View view, int position) { 98 | //在此处使用图片加载框架加载图片,demo中使用glide加载,可替换成自己项目中的图片加载框架 99 | TuchongEntity.FeedListBean.EntryBean listBean = ((TuchongEntity.FeedListBean.EntryBean) model); 100 | String url = "https://photo.tuchong.com/" + listBean.getImages().get(0).getUser_id() + "/f/" + listBean.getImages().get(0).getImg_id() + ".jpg"; 101 | Glide.with(MainActivity.this).load(url).placeholder(R.drawable.default_image).error(R.drawable.default_image).into((ImageView) view); 102 | } 103 | }); 104 | //代码设置框架占位图,也可在布局中设置 105 | mBanner.setBannerPlaceholderImg(R.mipmap.xbanner_logo, ImageView.ScaleType.CENTER_CROP); 106 | } 107 | 108 | /** 109 | * 初始化数据 110 | */ 111 | private void initData() { 112 | //加载网络图片资源 113 | String url = "https://api.tuchong.com/2/wall-paper/app"; 114 | OkHttpUtils 115 | .get() 116 | .url(url) 117 | .build() 118 | .execute(new StringCallback() { 119 | @Override 120 | public void onError(Call call, Exception e, int id) { 121 | 122 | Toast.makeText(MainActivity.this, "加载广告数据失败", Toast.LENGTH_SHORT).show(); 123 | } 124 | 125 | @Override 126 | public void onResponse(String response, int id) { 127 | TuchongEntity advertiseEntity = new Gson().fromJson(response, TuchongEntity.class); 128 | List others = advertiseEntity.getFeedList(); 129 | final List data = new ArrayList<>(); 130 | for (int i = 0; i < others.size(); i++) { 131 | TuchongEntity.FeedListBean feedListBean = others.get(i); 132 | if ("post".equals(feedListBean.getType())) { 133 | data.add(feedListBean.getEntry()); 134 | } 135 | } 136 | //刷新数据之后,需要重新设置是否支持自动轮播 137 | mBanner.setAutoPlayAble(true); 138 | mBanner.setBannerData(data); 139 | } 140 | }); 141 | } 142 | 143 | @Override 144 | public void onClick(View view) { 145 | mBanner.setBannerCurrentItem(2); 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /sample/src/main/java/com/stx/xhb/demo/MyApplication.java: -------------------------------------------------------------------------------- 1 | package com.stx.xhb.demo; 2 | 3 | import android.app.Application; 4 | 5 | import com.blankj.utilcode.util.Utils; 6 | import com.bumptech.glide.request.target.ViewTarget; 7 | import com.facebook.drawee.backends.pipeline.Fresco; 8 | import com.zhy.http.okhttp.OkHttpUtils; 9 | import com.zhy.http.okhttp.log.LoggerInterceptor; 10 | 11 | import java.util.concurrent.TimeUnit; 12 | 13 | import okhttp3.OkHttpClient; 14 | import xyz.doikki.videoplayer.ijk.IjkPlayerFactory; 15 | import xyz.doikki.videoplayer.player.AndroidMediaPlayerFactory; 16 | import xyz.doikki.videoplayer.player.VideoViewConfig; 17 | import xyz.doikki.videoplayer.player.VideoViewManager; 18 | 19 | /** 20 | * @author Mr.xiao 21 | * @date 16/9/23 22 | */ 23 | public class MyApplication extends Application { 24 | @Override 25 | public void onCreate() { 26 | super.onCreate(); 27 | ViewTarget.setTagId(R.id.glide_tag); 28 | //Fresco初始化 29 | Fresco.initialize(this); 30 | OkHttpClient okHttpClient = new OkHttpClient.Builder() 31 | .addInterceptor(new LoggerInterceptor("Xbanner")) 32 | .connectTimeout(10000L, TimeUnit.MILLISECONDS) 33 | .readTimeout(10000L, TimeUnit.MILLISECONDS) 34 | .build(); 35 | OkHttpUtils.initClient(okHttpClient); 36 | Utils.init(this); 37 | 38 | VideoViewManager.setConfig(VideoViewConfig.newBuilder() 39 | //使用使用IjkPlayer解码 40 | .setPlayerFactory(IjkPlayerFactory.create()) 41 | //使用MediaPlayer解码 42 | .setPlayerFactory(AndroidMediaPlayerFactory.create()) 43 | .build()); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /sample/src/main/java/com/stx/xhb/demo/RecyclerViewActivity.java: -------------------------------------------------------------------------------- 1 | package com.stx.xhb.demo; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.widget.SwipeRefreshLayout; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.support.v7.widget.DividerItemDecoration; 7 | import android.support.v7.widget.LinearLayoutManager; 8 | import android.support.v7.widget.RecyclerView; 9 | import android.view.View; 10 | import android.widget.ImageView; 11 | import android.widget.LinearLayout; 12 | import android.widget.Toast; 13 | 14 | import com.blankj.utilcode.util.ToastUtils; 15 | import com.bumptech.glide.Glide; 16 | import com.google.gson.Gson; 17 | import com.stx.xhb.xbanner.XBanner; 18 | import com.stx.xhb.demo.adapter.RvListAdapter; 19 | import com.stx.xhb.demo.entity.TuchongEntity; 20 | import com.zhy.http.okhttp.OkHttpUtils; 21 | import com.zhy.http.okhttp.callback.StringCallback; 22 | 23 | import java.util.ArrayList; 24 | import java.util.Arrays; 25 | import java.util.List; 26 | 27 | import okhttp3.Call; 28 | 29 | /** 30 | * Use In RecyclerView 31 | */ 32 | public class RecyclerViewActivity extends AppCompatActivity { 33 | 34 | private XBanner mXBanner; 35 | private SwipeRefreshLayout mRefreshLayout; 36 | private RecyclerView recyclerView; 37 | 38 | @Override 39 | protected void onCreate(Bundle savedInstanceState) { 40 | super.onCreate(savedInstanceState); 41 | setContentView(R.layout.activity_recyclerview); 42 | initView(); 43 | setListener(); 44 | requsetData(); 45 | } 46 | 47 | 48 | /** 49 | * 初始化View 50 | */ 51 | private void initView() { 52 | recyclerView = findViewById(R.id.rv); 53 | recyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL)); 54 | recyclerView.setLayoutManager(new LinearLayoutManager(this)); 55 | RvListAdapter rvListAdapter = new RvListAdapter(R.layout.list_item_text, Arrays.asList(getResources().getStringArray(R.array.transforms))); 56 | recyclerView.setAdapter(rvListAdapter); 57 | mRefreshLayout = findViewById(R.id.refresh_layout); 58 | 59 | // 初始化HeaderView 60 | View headerView = View.inflate(this, R.layout.ad_head, null); 61 | mXBanner = headerView.findViewById(R.id.banner); 62 | mXBanner.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, ScreenUtil.getScreenWidth(this) / 2)); 63 | rvListAdapter.addHeaderView(headerView); 64 | mRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { 65 | @Override 66 | public void onRefresh() { 67 | requsetData(); 68 | mRefreshLayout.setRefreshing(false); 69 | } 70 | }); 71 | } 72 | 73 | /** 74 | * 初始化XBanner 75 | */ 76 | private void setListener() { 77 | //设置广告图片点击事件 78 | mXBanner.setOnItemClickListener(new XBanner.OnItemClickListener() { 79 | @Override 80 | public void onItemClick(XBanner banner, Object model, View view, int position) { 81 | ToastUtils.showShort("点击了第" + (position + 1) + "图片"); 82 | } 83 | }); 84 | //加载广告图片 85 | mXBanner.loadImage(new XBanner.XBannerAdapter() { 86 | @Override 87 | public void loadBanner(XBanner banner, Object model, View view, int position) { 88 | //在此处使用图片加载框架加载图片,demo中使用glide加载,可替换成自己项目中的图片加载框架 89 | TuchongEntity.FeedListBean.EntryBean listBean = ((TuchongEntity.FeedListBean.EntryBean) model); 90 | String url = "https://photo.tuchong.com/" + listBean.getImages().get(0).getUser_id() + "/f/" + listBean.getImages().get(0).getImg_id() + ".jpg"; 91 | Glide.with(RecyclerViewActivity.this).load(url).placeholder(R.drawable.default_image).error(R.drawable.default_image).into((ImageView) view); 92 | } 93 | }); 94 | } 95 | 96 | /** 97 | * 加载网络数据 98 | */ 99 | private void requsetData() { 100 | //加载网络图片资源 101 | String url = "https://api.tuchong.com/2/wall-paper/app"; 102 | OkHttpUtils 103 | .get() 104 | .url(url) 105 | .build() 106 | .execute(new StringCallback() { 107 | @Override 108 | public void onError(Call call, Exception e, int id) { 109 | Toast.makeText(RecyclerViewActivity.this, "加载广告数据失败", Toast.LENGTH_SHORT).show(); 110 | } 111 | 112 | @Override 113 | public void onResponse(String response, int id) { 114 | TuchongEntity advertiseEntity = new Gson().fromJson(response, TuchongEntity.class); 115 | List others = advertiseEntity.getFeedList(); 116 | List data = new ArrayList<>(); 117 | for (int i = 0; i < others.size(); i++) { 118 | TuchongEntity.FeedListBean feedListBean = others.get(i); 119 | if ("post".equals(feedListBean.getType())) { 120 | data.add(feedListBean.getEntry()); 121 | } 122 | } 123 | //刷新数据之后,需要重新设置是否支持自动轮播 124 | mXBanner.setAutoPlayAble(data.size() > 1); 125 | mXBanner.setBannerData(data); 126 | } 127 | }); 128 | } 129 | 130 | } 131 | -------------------------------------------------------------------------------- /sample/src/main/java/com/stx/xhb/demo/ScreenUtil.java: -------------------------------------------------------------------------------- 1 | package com.stx.xhb.demo; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.util.DisplayMetrics; 6 | import android.view.Display; 7 | import android.view.WindowManager; 8 | 9 | /** 10 | * @author Mr.xiao 11 | */ 12 | public class ScreenUtil { 13 | 14 | private static final int[] APPCOMPAT_CHECK_ATTRS = {R.attr.colorPrimary}; 15 | 16 | public static void checkAppCompatTheme(Context context) { 17 | TypedArray a = context.obtainStyledAttributes(APPCOMPAT_CHECK_ATTRS); 18 | final boolean failed = !a.hasValue(0); 19 | if (a != null) { 20 | a.recycle(); 21 | } 22 | if (failed) { 23 | throw new IllegalArgumentException("You need to use a Theme.AppCompat theme " 24 | + "(or descendant) with the design library."); 25 | } 26 | } 27 | 28 | public static int px2sp(Context context, float pxValue) { 29 | final float fontScale = context.getResources().getDisplayMetrics().scaledDensity; 30 | return (int) (pxValue / fontScale + 0.5f); 31 | } 32 | 33 | public static int dp2px(Context context, int dp) { 34 | DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics(); 35 | return (int) ((dp * displayMetrics.density) + 0.5); 36 | } 37 | 38 | public static int dp2px(Context context, double dp) { 39 | DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics(); 40 | return (int) ((dp * displayMetrics.density) + 0.5); 41 | } 42 | 43 | public static int getScreenWidth(Context context) { 44 | DisplayMetrics dm = new DisplayMetrics(); 45 | //((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(dm); 46 | 47 | WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); 48 | Display display = wm.getDefaultDisplay(); 49 | display.getMetrics(dm); 50 | 51 | return dm.widthPixels; 52 | } 53 | 54 | /** 55 | * 获取屏幕的高 56 | */ 57 | public static int getScreenHeight(Context context) { 58 | return context.getResources().getDisplayMetrics().heightPixels; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /sample/src/main/java/com/stx/xhb/demo/UserInFragmentActivity.java: -------------------------------------------------------------------------------- 1 | package com.stx.xhb.demo; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v4.app.Fragment; 6 | import android.support.v7.app.AppCompatActivity; 7 | import android.widget.RadioButton; 8 | import android.widget.RadioGroup; 9 | 10 | import com.blankj.utilcode.util.FragmentUtils; 11 | import com.stx.xhb.demo.fragment.BannerFragment; 12 | import com.stx.xhb.demo.fragment.NumberIndicatorFragment; 13 | 14 | import java.util.ArrayList; 15 | import java.util.List; 16 | 17 | /** 18 | * @author: xiaohaibin. 19 | * @time: 2019/10/17 20 | * @mail:xhb_199409@163.com 21 | * @github:https://github.com/xiaohaibin 22 | * @describe: Fragment中使用 23 | */ 24 | public class UserInFragmentActivity extends AppCompatActivity { 25 | 26 | private List mFragmentList; 27 | 28 | @Override 29 | protected void onCreate(@Nullable Bundle savedInstanceState) { 30 | super.onCreate(savedInstanceState); 31 | setContentView(R.layout.activity_user_in_fragment); 32 | RadioGroup rbTab = findViewById(R.id.rg_tab); 33 | RadioButton radioButton= (RadioButton) rbTab.getChildAt(0); 34 | radioButton.setChecked(true); 35 | mFragmentList=new ArrayList<>(); 36 | mFragmentList.add(BannerFragment.newInstance()); 37 | mFragmentList.add(NumberIndicatorFragment.newInstance()); 38 | mFragmentList.add(BannerFragment.newInstance()); 39 | mFragmentList.add(BannerFragment.newInstance()); 40 | FragmentUtils.add(getSupportFragmentManager(),mFragmentList,R.id.fragment_content,0); 41 | rbTab.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { 42 | @Override 43 | public void onCheckedChanged(RadioGroup group, int checkedId) { 44 | switch (checkedId) { 45 | case R.id.tab_1: 46 | FragmentUtils.showHide(0,mFragmentList); 47 | break; 48 | case R.id.tab_2: 49 | FragmentUtils.showHide(1,mFragmentList); 50 | break; 51 | case R.id.tab_3: 52 | FragmentUtils.showHide(2,mFragmentList); 53 | break; 54 | case R.id.tab_4: 55 | FragmentUtils.showHide(3,mFragmentList); 56 | break; 57 | default: 58 | break; 59 | } 60 | } 61 | }); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /sample/src/main/java/com/stx/xhb/demo/VideoViewActivity.java: -------------------------------------------------------------------------------- 1 | package com.stx.xhb.demo; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.view.ViewPager; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.util.Log; 7 | import android.view.View; 8 | import android.widget.Toast; 9 | 10 | import com.blankj.utilcode.util.ToastUtils; 11 | import com.stx.xhb.demo.entity.CustomViewsInfo; 12 | import com.stx.xhb.demo.holder.BannerHolderCreator; 13 | import com.stx.xhb.xbanner.XBanner; 14 | 15 | import java.util.ArrayList; 16 | import java.util.List; 17 | 18 | 19 | /** 20 | * 视频图片混合轮播 21 | * Demo只是给个例子参考,更多自定义功能需要根据自身需求去实现 22 | * 框架本身只是个轮播框架,支持各种自定义布局 23 | */ 24 | public class VideoViewActivity extends AppCompatActivity { 25 | 26 | @Override 27 | protected void onCreate(Bundle savedInstanceState) { 28 | super.onCreate(savedInstanceState); 29 | setContentView(R.layout.activity_custom_views); 30 | initView(); 31 | } 32 | 33 | private void initView() { 34 | XBanner banner = (XBanner) findViewById(R.id.banner); 35 | List data = new ArrayList<>(); 36 | data.add(new CustomViewsInfo("https://photo.tuchong.com/250829/f/31548923.jpg")); 37 | data.add(new CustomViewsInfo("https://photo.tuchong.com/46728/f/20138526.jpg")); 38 | data.add(new CustomViewsInfo("https://photo.tuchong.com/392724/f/16858773.jpg")); 39 | data.add(new CustomViewsInfo("https://photo.tuchong.com/408963/f/18401047.jpg")); 40 | final BannerHolderCreator holderCreator = new BannerHolderCreator(); 41 | banner.setBannerData(data, holderCreator); 42 | banner.setOnItemClickListener(new XBanner.OnItemClickListener() { 43 | @Override 44 | public void onItemClick(XBanner banner, Object model, View view, int position) { 45 | ToastUtils.showShort("点击了" + position); 46 | } 47 | }); 48 | banner.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { 49 | @Override 50 | public void onPageScrolled(int i, float v, int i1) { 51 | Log.i("onPageScrolled=", i + ""); 52 | } 53 | 54 | @Override 55 | public void onPageSelected(int i) { 56 | Log.i("onPageSelected=", i + ""); 57 | if (i == 0) { 58 | holderCreator.videoViewHolder.videoView.start(); 59 | } else { 60 | holderCreator.videoViewHolder.videoView.pause(); 61 | } 62 | } 63 | 64 | @Override 65 | public void onPageScrollStateChanged(int i) { 66 | Log.i("ScrollStateChanged=", i + ""); 67 | } 68 | }); 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /sample/src/main/java/com/stx/xhb/demo/adapter/RvListAdapter.java: -------------------------------------------------------------------------------- 1 | package com.stx.xhb.demo.adapter; 2 | 3 | import android.support.annotation.Nullable; 4 | 5 | import com.chad.library.adapter.base.BaseQuickAdapter; 6 | import com.chad.library.adapter.base.BaseViewHolder; 7 | import com.stx.xhb.demo.R; 8 | 9 | 10 | import org.jetbrains.annotations.NotNull; 11 | 12 | import java.util.List; 13 | 14 | public class RvListAdapter extends BaseQuickAdapter { 15 | 16 | public RvListAdapter(int layoutResId, @Nullable List data) { 17 | super(layoutResId, data); 18 | } 19 | 20 | @Override 21 | protected void convert(@NotNull BaseViewHolder baseViewHolder, String s) { 22 | baseViewHolder.setText(R.id.text2, s); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /sample/src/main/java/com/stx/xhb/demo/entity/CustomViewsInfo.java: -------------------------------------------------------------------------------- 1 | package com.stx.xhb.demo.entity; 2 | 3 | 4 | import com.stx.xhb.xbanner.entity.BaseBannerInfo; 5 | 6 | /** 7 | * author: xiaohaibin. 8 | * time: 2018/12/3 9 | * mail:xhb_199409@163.com 10 | * github:https://github.com/xiaohaibin 11 | * describe: CustomViewsInfo 继承 SimpleBannerInfo 根据个人情况重载两个方法 12 | */ 13 | public class CustomViewsInfo implements BaseBannerInfo { 14 | 15 | private String info; 16 | 17 | public CustomViewsInfo(String info) { 18 | this.info = info; 19 | } 20 | 21 | @Override 22 | public String getXBannerUrl() { 23 | return info; 24 | } 25 | 26 | @Override 27 | public String getXBannerTitle() { 28 | return null; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /sample/src/main/java/com/stx/xhb/demo/entity/ImagesBean.java: -------------------------------------------------------------------------------- 1 | package com.stx.xhb.demo.entity; 2 | 3 | /** 4 | * author: xiaohaibin. 5 | * time: 2018/10/19 6 | * mail:xhb_199409@163.com 7 | * github:https://github.com/xiaohaibin 8 | */ 9 | public class ImagesBean { 10 | 11 | /** 12 | * img_id : 21702193 13 | * user_id : 489217 14 | * title : hongjl-1-10-b 15 | * excerpt : 再战房山这条七拐八弯的山路。 路上车少,这次索性自己开车拉出尾灯拖影效果,用这张图片记忆流走的时光。 特别感谢一路同行的贝城大哥和昆昆虫兄弟,此行获益匪浅,嗨啊! 16 | * width : 2589 17 | * height : 3500 18 | * description : 再战房山这条七拐八弯的山路。 路上车少,这次索性自己开车拉出尾灯拖影效果,用这张图片记忆流走的时光。 特别感谢一路同行的贝城大哥和昆昆虫兄弟,此行获益匪浅,嗨啊! 19 | * isAuthorTK : true 20 | */ 21 | 22 | private int img_id; 23 | private int user_id; 24 | private String title; 25 | private String excerpt; 26 | private int width; 27 | private int height; 28 | private String description; 29 | private boolean isAuthorTK; 30 | 31 | public int getImg_id() { 32 | return img_id; 33 | } 34 | 35 | public void setImg_id(int img_id) { 36 | this.img_id = img_id; 37 | } 38 | 39 | public int getUser_id() { 40 | return user_id; 41 | } 42 | 43 | public void setUser_id(int user_id) { 44 | this.user_id = user_id; 45 | } 46 | 47 | public String getTitle() { 48 | return title; 49 | } 50 | 51 | public void setTitle(String title) { 52 | this.title = title; 53 | } 54 | 55 | public String getExcerpt() { 56 | return excerpt; 57 | } 58 | 59 | public void setExcerpt(String excerpt) { 60 | this.excerpt = excerpt; 61 | } 62 | 63 | public int getWidth() { 64 | return width; 65 | } 66 | 67 | public void setWidth(int width) { 68 | this.width = width; 69 | } 70 | 71 | public int getHeight() { 72 | return height; 73 | } 74 | 75 | public void setHeight(int height) { 76 | this.height = height; 77 | } 78 | 79 | public String getDescription() { 80 | return description; 81 | } 82 | 83 | public void setDescription(String description) { 84 | this.description = description; 85 | } 86 | 87 | public boolean isIsAuthorTK() { 88 | return isAuthorTK; 89 | } 90 | 91 | public void setIsAuthorTK(boolean isAuthorTK) { 92 | this.isAuthorTK = isAuthorTK; 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /sample/src/main/java/com/stx/xhb/demo/entity/TuchongEntity.java: -------------------------------------------------------------------------------- 1 | package com.stx.xhb.demo.entity; 2 | 3 | 4 | import com.stx.xhb.xbanner.entity.BaseBannerInfo; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * author: xiaohaibin. 10 | * time: 2018/10/19 11 | * mail:xhb_199409@163.com 12 | * github:https://github.com/xiaohaibin 13 | * describe: 14 | */ 15 | public class TuchongEntity { 16 | 17 | 18 | private String tos_name; 19 | private boolean more; 20 | private String result; 21 | private List feedList; 22 | 23 | public String getTos_name() { 24 | return tos_name; 25 | } 26 | 27 | public void setTos_name(String tos_name) { 28 | this.tos_name = tos_name; 29 | } 30 | 31 | public boolean isMore() { 32 | return more; 33 | } 34 | 35 | public void setMore(boolean more) { 36 | this.more = more; 37 | } 38 | 39 | public String getResult() { 40 | return result; 41 | } 42 | 43 | public void setResult(String result) { 44 | this.result = result; 45 | } 46 | 47 | public List getFeedList() { 48 | return feedList; 49 | } 50 | 51 | public void setFeedList(List feedList) { 52 | this.feedList = feedList; 53 | } 54 | 55 | public static class FeedListBean { 56 | 57 | private String type; 58 | private EntryBean entry; 59 | 60 | public String getType() { 61 | return type; 62 | } 63 | 64 | public void setType(String type) { 65 | this.type = type; 66 | } 67 | 68 | public EntryBean getEntry() { 69 | return entry; 70 | } 71 | 72 | public void setEntry(EntryBean entry) { 73 | this.entry = entry; 74 | } 75 | 76 | public static class EntryBean implements BaseBannerInfo { 77 | 78 | private String vid; 79 | private String video_id; 80 | private String title; 81 | private String content; 82 | private String type; 83 | private AuthorBean author; 84 | private String cover; 85 | private String raw_cover; 86 | private int favorites; 87 | private int views; 88 | private String video_width; 89 | private String video_height; 90 | private String created; 91 | private String share_url; 92 | private String share_cover; 93 | private String duration; 94 | private boolean is_recommend; 95 | private String comments; 96 | private String passed_time; 97 | private boolean is_ultra; 98 | private boolean collected; 99 | private int collect_num; 100 | private String gif_cover; 101 | private List category; 102 | private String url; 103 | private List images; 104 | 105 | @Override 106 | public String getXBannerUrl() { 107 | return "https://photo.tuchong.com/" + getImages().get(0).getUser_id() + "/f/" + getImages().get(0).getImg_id() + ".jpg"; 108 | } 109 | 110 | @Override 111 | public String getXBannerTitle() { 112 | return getTitle(); 113 | } 114 | 115 | public List getImages() { 116 | return images; 117 | } 118 | 119 | public String getUrl() { 120 | return url; 121 | } 122 | 123 | public String getVid() { 124 | return vid; 125 | } 126 | 127 | public void setVid(String vid) { 128 | this.vid = vid; 129 | } 130 | 131 | public String getVideo_id() { 132 | return video_id; 133 | } 134 | 135 | public void setVideo_id(String video_id) { 136 | this.video_id = video_id; 137 | } 138 | 139 | public String getTitle() { 140 | return title; 141 | } 142 | 143 | public void setTitle(String title) { 144 | this.title = title; 145 | } 146 | 147 | public String getContent() { 148 | return content; 149 | } 150 | 151 | public void setContent(String content) { 152 | this.content = content; 153 | } 154 | 155 | public String getType() { 156 | return type; 157 | } 158 | 159 | public void setType(String type) { 160 | this.type = type; 161 | } 162 | 163 | public AuthorBean getAuthor() { 164 | return author; 165 | } 166 | 167 | public void setAuthor(AuthorBean author) { 168 | this.author = author; 169 | } 170 | 171 | public String getCover() { 172 | return cover; 173 | } 174 | 175 | public void setCover(String cover) { 176 | this.cover = cover; 177 | } 178 | 179 | public String getRaw_cover() { 180 | return raw_cover; 181 | } 182 | 183 | public void setRaw_cover(String raw_cover) { 184 | this.raw_cover = raw_cover; 185 | } 186 | 187 | public int getFavorites() { 188 | return favorites; 189 | } 190 | 191 | public void setFavorites(int favorites) { 192 | this.favorites = favorites; 193 | } 194 | 195 | public int getViews() { 196 | return views; 197 | } 198 | 199 | public void setViews(int views) { 200 | this.views = views; 201 | } 202 | 203 | public String getVideo_width() { 204 | return video_width; 205 | } 206 | 207 | public void setVideo_width(String video_width) { 208 | this.video_width = video_width; 209 | } 210 | 211 | public String getVideo_height() { 212 | return video_height; 213 | } 214 | 215 | public void setVideo_height(String video_height) { 216 | this.video_height = video_height; 217 | } 218 | 219 | public String getCreated() { 220 | return created; 221 | } 222 | 223 | public void setCreated(String created) { 224 | this.created = created; 225 | } 226 | 227 | public String getShare_url() { 228 | return share_url; 229 | } 230 | 231 | public void setShare_url(String share_url) { 232 | this.share_url = share_url; 233 | } 234 | 235 | public String getShare_cover() { 236 | return share_cover; 237 | } 238 | 239 | public void setShare_cover(String share_cover) { 240 | this.share_cover = share_cover; 241 | } 242 | 243 | public String getDuration() { 244 | return duration; 245 | } 246 | 247 | public void setDuration(String duration) { 248 | this.duration = duration; 249 | } 250 | 251 | public boolean isIs_recommend() { 252 | return is_recommend; 253 | } 254 | 255 | public void setIs_recommend(boolean is_recommend) { 256 | this.is_recommend = is_recommend; 257 | } 258 | 259 | public String getComments() { 260 | return comments; 261 | } 262 | 263 | public void setComments(String comments) { 264 | this.comments = comments; 265 | } 266 | 267 | public String getPassed_time() { 268 | return passed_time; 269 | } 270 | 271 | public void setPassed_time(String passed_time) { 272 | this.passed_time = passed_time; 273 | } 274 | 275 | public boolean isIs_ultra() { 276 | return is_ultra; 277 | } 278 | 279 | public void setIs_ultra(boolean is_ultra) { 280 | this.is_ultra = is_ultra; 281 | } 282 | 283 | public boolean isCollected() { 284 | return collected; 285 | } 286 | 287 | public void setCollected(boolean collected) { 288 | this.collected = collected; 289 | } 290 | 291 | public int getCollect_num() { 292 | return collect_num; 293 | } 294 | 295 | public void setCollect_num(int collect_num) { 296 | this.collect_num = collect_num; 297 | } 298 | 299 | public String getGif_cover() { 300 | return gif_cover; 301 | } 302 | 303 | public void setGif_cover(String gif_cover) { 304 | this.gif_cover = gif_cover; 305 | } 306 | 307 | public List getCategory() { 308 | return category; 309 | } 310 | 311 | public void setCategory(List category) { 312 | this.category = category; 313 | } 314 | 315 | public static class AuthorBean { 316 | /** 317 | * site_id : 1370250 318 | * type : user 319 | * name : 炙热的橙 320 | * domain : 321 | * description : 微博:炙热的橙 322 | * followers : 7841 323 | * url : https://tuchong.com/1370250/ 324 | * icon : https://s1.tuchong.com/sites/137/1370250/logo_small.jpg?6 325 | * verified : false 326 | * verified_type : 0 327 | * verified_reason : 328 | * verifications : 0 329 | * verification_list : [] 330 | */ 331 | 332 | private int site_id; 333 | private String type; 334 | private String name; 335 | private String domain; 336 | private String description; 337 | private int followers; 338 | private String url; 339 | private String icon; 340 | private boolean verified; 341 | private int verified_type; 342 | private String verified_reason; 343 | private int verifications; 344 | private List verification_list; 345 | 346 | public int getSite_id() { 347 | return site_id; 348 | } 349 | 350 | public void setSite_id(int site_id) { 351 | this.site_id = site_id; 352 | } 353 | 354 | public String getType() { 355 | return type; 356 | } 357 | 358 | public void setType(String type) { 359 | this.type = type; 360 | } 361 | 362 | public String getName() { 363 | return name; 364 | } 365 | 366 | public void setName(String name) { 367 | this.name = name; 368 | } 369 | 370 | public String getDomain() { 371 | return domain; 372 | } 373 | 374 | public void setDomain(String domain) { 375 | this.domain = domain; 376 | } 377 | 378 | public String getDescription() { 379 | return description; 380 | } 381 | 382 | public void setDescription(String description) { 383 | this.description = description; 384 | } 385 | 386 | public int getFollowers() { 387 | return followers; 388 | } 389 | 390 | public void setFollowers(int followers) { 391 | this.followers = followers; 392 | } 393 | 394 | public String getUrl() { 395 | return url; 396 | } 397 | 398 | public void setUrl(String url) { 399 | this.url = url; 400 | } 401 | 402 | public String getIcon() { 403 | return icon; 404 | } 405 | 406 | public void setIcon(String icon) { 407 | this.icon = icon; 408 | } 409 | 410 | public boolean isVerified() { 411 | return verified; 412 | } 413 | 414 | public void setVerified(boolean verified) { 415 | this.verified = verified; 416 | } 417 | 418 | public int getVerified_type() { 419 | return verified_type; 420 | } 421 | 422 | public void setVerified_type(int verified_type) { 423 | this.verified_type = verified_type; 424 | } 425 | 426 | public String getVerified_reason() { 427 | return verified_reason; 428 | } 429 | 430 | public void setVerified_reason(String verified_reason) { 431 | this.verified_reason = verified_reason; 432 | } 433 | 434 | public int getVerifications() { 435 | return verifications; 436 | } 437 | 438 | public void setVerifications(int verifications) { 439 | this.verifications = verifications; 440 | } 441 | 442 | public List getVerification_list() { 443 | return verification_list; 444 | } 445 | 446 | public void setVerification_list(List verification_list) { 447 | this.verification_list = verification_list; 448 | } 449 | } 450 | } 451 | } 452 | } 453 | -------------------------------------------------------------------------------- /sample/src/main/java/com/stx/xhb/demo/fragment/BannerFragment.java: -------------------------------------------------------------------------------- 1 | package com.stx.xhb.demo.fragment; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.app.Fragment; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.widget.ImageView; 9 | import android.widget.LinearLayout; 10 | import android.widget.Toast; 11 | 12 | import com.bumptech.glide.Glide; 13 | import com.google.gson.Gson; 14 | import com.stx.xhb.demo.R; 15 | import com.stx.xhb.demo.ScreenUtil; 16 | import com.stx.xhb.demo.entity.TuchongEntity; 17 | import com.stx.xhb.xbanner.XBanner; 18 | import com.zhy.http.okhttp.OkHttpUtils; 19 | import com.zhy.http.okhttp.callback.StringCallback; 20 | 21 | import java.util.ArrayList; 22 | import java.util.List; 23 | 24 | import okhttp3.Call; 25 | 26 | 27 | public class BannerFragment extends Fragment { 28 | 29 | private XBanner mBanner; 30 | 31 | public BannerFragment() { 32 | } 33 | 34 | public static BannerFragment newInstance() { 35 | return new BannerFragment(); 36 | } 37 | 38 | @Override 39 | public void onCreate(Bundle savedInstanceState) { 40 | super.onCreate(savedInstanceState); 41 | } 42 | 43 | @Override 44 | public View onCreateView(LayoutInflater inflater, ViewGroup container, 45 | Bundle savedInstanceState) { 46 | View view = LayoutInflater.from(getContext()).inflate(R.layout.fragment_banner, null); 47 | mBanner = view.findViewById(R.id.banner); 48 | mBanner.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, ScreenUtil.getScreenWidth(getContext()) / 2)); 49 | initBanner(); 50 | loadData(); 51 | return view; 52 | } 53 | 54 | 55 | /** 56 | * 初始化XBanner 57 | */ 58 | private void initBanner() { 59 | //设置广告图片点击事件 60 | mBanner.setOnItemClickListener(new XBanner.OnItemClickListener() { 61 | @Override 62 | public void onItemClick(XBanner banner, Object model, View view, int position) { 63 | Toast.makeText(getContext(), "点击了第" + (position + 1) + "图片", Toast.LENGTH_SHORT).show(); 64 | } 65 | }); 66 | //加载广告图片 67 | mBanner.loadImage(new XBanner.XBannerAdapter() { 68 | @Override 69 | public void loadBanner(XBanner banner, Object model, View view, int position) { 70 | //在此处使用图片加载框架加载图片,demo中使用glide加载,可替换成自己项目中的图片加载框架 71 | TuchongEntity.FeedListBean.EntryBean listBean = ((TuchongEntity.FeedListBean.EntryBean) model); 72 | String url = "https://photo.tuchong.com/" + listBean.getImages().get(0).getUser_id() + "/f/" + listBean.getImages().get(0).getImg_id() + ".jpg"; 73 | Glide.with(getActivity()).load(url).placeholder(R.drawable.default_image).error(R.drawable.default_image).into((ImageView) view); 74 | } 75 | }); 76 | List data = new ArrayList<>(); 77 | mBanner.setBannerData(data); 78 | } 79 | 80 | private void loadData() { 81 | //加载网络图片资源 82 | String url = "https://api.tuchong.com/2/wall-paper/app"; 83 | OkHttpUtils 84 | .get() 85 | .url(url) 86 | .build() 87 | .execute(new StringCallback() { 88 | @Override 89 | public void onError(Call call, Exception e, int id) { 90 | Toast.makeText(getContext(), "加载广告数据失败", Toast.LENGTH_SHORT).show(); 91 | } 92 | 93 | @Override 94 | public void onResponse(String response, int id) { 95 | TuchongEntity advertiseEntity = new Gson().fromJson(response, TuchongEntity.class); 96 | List others = advertiseEntity.getFeedList(); 97 | List data = new ArrayList<>(); 98 | for (int i = 0; i 1); 106 | mBanner.setBannerData(data); 107 | } 108 | }); 109 | } 110 | 111 | } 112 | -------------------------------------------------------------------------------- /sample/src/main/java/com/stx/xhb/demo/fragment/NumberIndicatorFragment.java: -------------------------------------------------------------------------------- 1 | package com.stx.xhb.demo.fragment; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.app.Fragment; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.widget.ImageView; 9 | import android.widget.LinearLayout; 10 | import android.widget.Toast; 11 | 12 | import com.bumptech.glide.Glide; 13 | import com.google.gson.Gson; 14 | import com.stx.xhb.demo.R; 15 | import com.stx.xhb.demo.ScreenUtil; 16 | import com.stx.xhb.demo.entity.TuchongEntity; 17 | import com.stx.xhb.xbanner.XBanner; 18 | import com.zhy.http.okhttp.OkHttpUtils; 19 | import com.zhy.http.okhttp.callback.StringCallback; 20 | 21 | import java.util.ArrayList; 22 | import java.util.List; 23 | 24 | import okhttp3.Call; 25 | 26 | 27 | public class NumberIndicatorFragment extends Fragment { 28 | 29 | private XBanner mBanner; 30 | 31 | public NumberIndicatorFragment() { 32 | } 33 | 34 | public static NumberIndicatorFragment newInstance() { 35 | return new NumberIndicatorFragment(); 36 | } 37 | 38 | @Override 39 | public void onCreate(Bundle savedInstanceState) { 40 | super.onCreate(savedInstanceState); 41 | } 42 | 43 | @Override 44 | public View onCreateView(LayoutInflater inflater, ViewGroup container, 45 | Bundle savedInstanceState) { 46 | View view = LayoutInflater.from(getContext()).inflate(R.layout.fragment_banner_indicator, null); 47 | mBanner = view.findViewById(R.id.banner); 48 | mBanner.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, ScreenUtil.getScreenWidth(getContext()) / 2)); 49 | initBanner(); 50 | loadData(); 51 | return view; 52 | } 53 | 54 | 55 | /** 56 | * 初始化XBanner 57 | */ 58 | private void initBanner() { 59 | //设置广告图片点击事件 60 | mBanner.setOnItemClickListener(new XBanner.OnItemClickListener() { 61 | @Override 62 | public void onItemClick(XBanner banner, Object model, View view, int position) { 63 | Toast.makeText(getContext(), "点击了第" + (position + 1) + "图片", Toast.LENGTH_SHORT).show(); 64 | } 65 | }); 66 | //加载广告图片 67 | mBanner.loadImage(new XBanner.XBannerAdapter() { 68 | @Override 69 | public void loadBanner(XBanner banner, Object model, View view, int position) { 70 | //在此处使用图片加载框架加载图片,demo中使用glide加载,可替换成自己项目中的图片加载框架 71 | TuchongEntity.FeedListBean.EntryBean listBean = ((TuchongEntity.FeedListBean.EntryBean) model); 72 | String url = "https://photo.tuchong.com/" + listBean.getImages().get(0).getUser_id() + "/f/" + listBean.getImages().get(0).getImg_id() + ".jpg"; 73 | Glide.with(getActivity()).load(url).placeholder(R.drawable.default_image).error(R.drawable.default_image).into((ImageView) view); 74 | } 75 | }); 76 | List data = new ArrayList<>(); 77 | mBanner.setBannerData(data); 78 | } 79 | 80 | private void loadData() { 81 | //加载网络图片资源 82 | String url = "https://api.tuchong.com/2/wall-paper/app"; 83 | OkHttpUtils 84 | .get() 85 | .url(url) 86 | .build() 87 | .execute(new StringCallback() { 88 | @Override 89 | public void onError(Call call, Exception e, int id) { 90 | Toast.makeText(getContext(), "加载广告数据失败", Toast.LENGTH_SHORT).show(); 91 | } 92 | 93 | @Override 94 | public void onResponse(String response, int id) { 95 | TuchongEntity advertiseEntity = new Gson().fromJson(response, TuchongEntity.class); 96 | List others = advertiseEntity.getFeedList(); 97 | List data = new ArrayList<>(); 98 | for (int i = 0; i 1); 106 | mBanner.setBannerData(data); 107 | } 108 | }); 109 | } 110 | 111 | } 112 | -------------------------------------------------------------------------------- /sample/src/main/java/com/stx/xhb/demo/holder/BannerHolderCreator.java: -------------------------------------------------------------------------------- 1 | package com.stx.xhb.demo.holder; 2 | 3 | import com.stx.xhb.xbanner.holder.HolderCreator; 4 | import com.stx.xhb.xbanner.holder.ViewHolder; 5 | 6 | public class BannerHolderCreator implements HolderCreator { 7 | public VideoViewHolder videoViewHolder; 8 | 9 | public BannerHolderCreator() { 10 | this.videoViewHolder = new VideoViewHolder(); 11 | } 12 | 13 | @Override 14 | public ViewHolder createViewHolder(int viewType) { 15 | if (viewType==0){ 16 | return videoViewHolder; 17 | } 18 | return new ImageViewHolder(); 19 | } 20 | 21 | @Override 22 | public int getViewType(int position) { 23 | return position; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /sample/src/main/java/com/stx/xhb/demo/holder/ImageViewHolder.java: -------------------------------------------------------------------------------- 1 | package com.stx.xhb.demo.holder; 2 | 3 | import android.view.View; 4 | import android.widget.ImageView; 5 | import com.bumptech.glide.Glide; 6 | import com.stx.xhb.demo.R; 7 | import com.stx.xhb.demo.entity.CustomViewsInfo; 8 | import com.stx.xhb.xbanner.holder.ViewHolder; 9 | 10 | public class ImageViewHolder implements ViewHolder { 11 | 12 | @Override 13 | public int getLayoutId() { 14 | return R.layout.layout_image_view; 15 | } 16 | 17 | @Override 18 | public void onBind(View itemView, CustomViewsInfo data, int position) { 19 | ImageView imageView = itemView.findViewById(R.id.iv); 20 | Glide.with(itemView.getContext()).load(data.getXBannerUrl()).placeholder(R.drawable.default_image).error(R.drawable.default_image).into(imageView); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /sample/src/main/java/com/stx/xhb/demo/holder/VideoViewHolder.java: -------------------------------------------------------------------------------- 1 | package com.stx.xhb.demo.holder; 2 | 3 | import android.view.View; 4 | 5 | import com.stx.xhb.demo.R; 6 | import com.stx.xhb.demo.entity.CustomViewsInfo; 7 | import com.stx.xhb.xbanner.holder.ViewHolder; 8 | 9 | import xyz.doikki.videocontroller.StandardVideoController; 10 | import xyz.doikki.videoplayer.player.VideoView; 11 | 12 | public class VideoViewHolder implements ViewHolder { 13 | public VideoView videoView; 14 | 15 | @Override 16 | public int getLayoutId() { 17 | return R.layout.layout_video_view; 18 | } 19 | 20 | @Override 21 | public void onBind(View itemView, CustomViewsInfo data, int position) { 22 | videoView = itemView.findViewById(R.id.player); 23 | videoView.setUrl("http://vfx.mtime.cn/Video/2019/03/18/mp4/190318231014076505.mp4"); 24 | StandardVideoController controller = new StandardVideoController(itemView.getContext()); 25 | controller.addDefaultControlComponent("标题", false); 26 | videoView.setVideoController(controller); //设置控制器 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable/banner_placeholder.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaohaibin/XBanner/c7b8563c1e565b2582e21968732e815c7c052cba/sample/src/main/res/drawable/banner_placeholder.jpg -------------------------------------------------------------------------------- /sample/src/main/res/drawable/default_image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaohaibin/XBanner/c7b8563c1e565b2582e21968732e815c7c052cba/sample/src/main/res/drawable/default_image.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable/point_normal.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable/point_now.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable/shape_noraml.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 7 | 8 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable/shape_number_indicator_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 10 | 11 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable/shape_round_8dp.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable/shape_selected.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | ¬¬ 5 | 6 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_clip_children_mode.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 14 | 15 | 19 | 20 | 35 | 36 | 50 | 51 | 52 | 71 | 72 | 73 | 90 | 91 | 92 | 110 | 111 | 112 | 113 | 114 | 115 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_custom_views.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 23 | 24 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_listview.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 24 | 25 | 30 |