├── .gitignore ├── .idea ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── inspectionProfiles │ ├── Project_Default.xml │ └── profiles_settings.xml ├── misc.xml ├── modules.xml └── runConfigurations.xml ├── README.md ├── app-release ├── app-release.aar └── build.gradle ├── app ├── .gitignore ├── build.gradle ├── keep_in_main_dex.txt ├── proguard-rules.pro └── src │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── allen │ │ │ └── recyclerview │ │ │ ├── MainApplication.java │ │ │ ├── activity │ │ │ ├── CustomView.java │ │ │ ├── GooglePlayActivity.java │ │ │ ├── HideActivity.java │ │ │ ├── HorizontalAdjustActivity.java │ │ │ ├── ListActivity.java │ │ │ ├── LocalRefreshActivity.java │ │ │ ├── MainActivity.java │ │ │ ├── OptimizeItem2ClickActivity.java │ │ │ ├── OptimizeItemClickActivity.java │ │ │ ├── RecyclerClickItemActivity.java │ │ │ ├── RotateActivity.java │ │ │ ├── TestActivity.java │ │ │ └── VerticalAdjustActivity.java │ │ │ ├── adapter │ │ │ ├── GooglePlayAdapter.java │ │ │ ├── GooglePlayItemAdapter.java │ │ │ ├── HideAdapter.java │ │ │ ├── HomeAdapter.java │ │ │ ├── HorizationAdapter.java │ │ │ ├── OptimeizeClickAdapter.java │ │ │ ├── OptimeizeGridItemClickAdapter.java │ │ │ ├── QuickClickAdapter.java │ │ │ └── RefreshAdapter.java │ │ │ ├── component │ │ │ └── CanvasView.java │ │ │ ├── data │ │ │ └── DataServer.java │ │ │ ├── entry │ │ │ ├── Home.java │ │ │ ├── MarryInfo.java │ │ │ ├── News.java │ │ │ └── Status.java │ │ │ └── view │ │ │ └── ScrollByView.java │ └── res │ │ ├── drawable-v21 │ │ └── touch_bg.xml │ │ ├── drawable │ │ ├── selector_item.xml │ │ ├── selector_item_child.xml │ │ └── touch_bg.xml │ │ ├── layout │ │ ├── activity_custom_view.xml │ │ ├── activity_hide.xml │ │ ├── activity_horizontal_adjust.xml │ │ ├── activity_list.xml │ │ ├── activity_local_refresh.xml │ │ ├── activity_main.xml │ │ ├── activity_optimize_item_click.xml │ │ ├── activity_recycler_click.xml │ │ ├── activity_recyclerview_nest.xml │ │ ├── activity_rotate.xml │ │ ├── activity_test.xml │ │ ├── content_optimize_item_click.xml │ │ ├── item.xml │ │ ├── item_activity.xml │ │ ├── item_click_view.xml │ │ ├── item_googleplay.xml │ │ ├── item_grid_optimeize.xml │ │ ├── item_marray.xml │ │ ├── item_news_title.xml │ │ ├── item_optimeize.xml │ │ └── text_row_item.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ ├── def_head.png │ │ ├── ic_launcher.png │ │ └── retweet.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── attrs_canvas_view.xml │ │ ├── attrs_scroll_by_view.xml │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── refs.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── allen │ └── recyclerview │ └── ExampleUnitTest.java ├── build.gradle ├── gif ├── divide.gif ├── news.jpg └── sample1.gif ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── library-release ├── build.gradle └── library-release.aar ├── library ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── chad │ │ └── library │ │ └── adapter │ │ └── base │ │ ├── BaseItemDraggableAdapter.java │ │ ├── BaseMultiItemQuickAdapter.java │ │ ├── BaseQuickAdapter.java │ │ ├── BaseSectionQuickAdapter.java │ │ ├── BaseViewHolder.java │ │ ├── animation │ │ ├── AlphaInAnimation.java │ │ ├── BaseAnimation.java │ │ ├── ScaleInAnimation.java │ │ ├── SlideInBottomAnimation.java │ │ ├── SlideInLeftAnimation.java │ │ └── SlideInRightAnimation.java │ │ ├── callback │ │ └── ItemDragAndSwipeCallback.java │ │ ├── entity │ │ ├── AbstractExpandableItem.java │ │ ├── IExpandable.java │ │ ├── MultiItemEntity.java │ │ └── SectionEntity.java │ │ ├── listener │ │ ├── OnItemChildClickListener.java │ │ ├── OnItemChildLongClickListener.java │ │ ├── OnItemClickListener.java │ │ ├── OnItemDragListener.java │ │ ├── OnItemLongClickListener.java │ │ ├── OnItemSwipeListener.java │ │ └── SimpleClickListener.java │ │ ├── loadmore │ │ ├── LoadMoreView.java │ │ └── SimpleLoadMoreView.java │ │ └── util │ │ └── TouchEventUtil.java │ └── res │ ├── drawable │ ├── sample_footer_loading.png │ └── sample_footer_loading_progress.xml │ ├── layout │ └── quick_view_load_more.xml │ ├── values-en │ └── strings.xml │ └── values │ ├── dimens.xml │ ├── ids.xml │ └── strings.xml ├── mylibrary ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── allen │ │ └── mylibrary │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ └── res │ │ └── values │ │ └── strings.xml │ └── test │ └── java │ └── com │ └── allen │ └── mylibrary │ └── ExampleUnitTest.java ├── recyclerview.jks └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | /.idea/ 11 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 10 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | 47 | 48 | 49 | 50 | 1.8 51 | 52 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 68 | 69 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Recyclerview 常见问题处理(持续更新维护中...) 2 | 3 | ##1. RecyclerView滚动定位 4 | 5 | 经常在开发中,需要将Recyclerview滑动到某个位置,然后定位这一个具体项,将他显示到顶部,用RecyclerView的默认移动的方法并不能实现这一点 6 | 但是,利用LinearLayoutManager,可以很方便的实现这一点。 7 | 不多说,直接上代码 8 | 9 | ```java 10 | 11 | int positon ="你指定滚动的位置"; 12 | layoutManager.scrollToPositionWithOffset(positon,0); 13 | layoutManager.setStackFromEnd(true); 14 | 15 | ``` 16 | 17 | ![演示动画](./gif/sample1.gif) 18 | 19 | 20 | 21 | ##2. Recyclerview 动态调整View的宽高 22 | 23 | 假如你有 10个item ,产品偶尔会让你一屏幕适配6个 ,剩余的可以滚动 24 | 下面介绍两种情况下的处理方案,一种是水平布局,一种是垂直布局 25 | ![网易效果](./gif/news.jpg) 26 | 27 | ###方便的处理办法1:修改适配器 28 | 29 | ```java 30 | 31 | public class HorizationAdapter extends BaseQuickAdapter { 32 | private LayoutInflater layoutInflater; 33 | private int N ; 34 | 35 | 36 | public HorizationAdapter(Context mContex, int N) { 37 | super(item, DataServer.getNews()); 38 | this.N =N; 39 | layoutInflater =LayoutInflater.from(mContex); 40 | } 41 | 42 | 43 | @Override 44 | protected void convert(final BaseViewHolder newsViewHolder, final News news) { 45 | newsViewHolder.setText(R.id.tv_title,news.title); 46 | } 47 | @Override 48 | protected View getItemView(final int layoutResId, final ViewGroup parent) { 49 | View view = layoutInflater.inflate(R.layout.item_news_title, parent, false); 50 | view.setMinimumWidth(parent.getWidth() / N); 51 | LinearLayout.LayoutParams parms = new LinearLayout.LayoutParams(parent.getWidth() / N, ViewGroup.LayoutParams.MATCH_PARENT); 52 | view.setLayoutParams(parms); 53 | return view; 54 | } 55 | 56 | } 57 | 58 | ``` 59 | 60 | 最终效果图: 61 | ![效果图](./gif/divide.gif) 62 | -------------------------------------------------------------------------------- /app-release/app-release.aar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AllenCoder/Recyclerview/0daaf59b873c544824e90a3837282b62a2f71176/app-release/app-release.aar -------------------------------------------------------------------------------- /app-release/build.gradle: -------------------------------------------------------------------------------- 1 | configurations.maybeCreate("default") 2 | artifacts.add("default", file('app-release.aar')) -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | //apply plugin: 'view-inspector' 3 | apply plugin: 'com.jakewharton.hugo' 4 | android { 5 | compileSdkVersion 25 6 | buildToolsVersion '25.0.2' 7 | defaultConfig { 8 | applicationId "com.allen.recyclerview" 9 | minSdkVersion 15 10 | targetSdkVersion 25 11 | versionCode 1 12 | versionName "1.0" 13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 14 | } 15 | buildTypes { 16 | release { 17 | minifyEnabled false 18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 19 | } 20 | } 21 | } 22 | 23 | dependencies { 24 | compile fileTree(include: ['*.jar'], dir: 'libs') 25 | // compile 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.7.0' 26 | compile project(':app-release') 27 | compile 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.13' 28 | // compile project(':library') 29 | // compile 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.7.8' 30 | // compile project(':library-release') 31 | // Because RxAndroid releases are few and far between, it is recommended you also 32 | // explicitly depend on RxJava's latest version for bug fixes and new features. 33 | compile 'com.android.support:design:25.3.0' 34 | compile 'com.android.support:cardview-v7:25.3.0' 35 | compile 'com.android.support:appcompat-v7:25.2.0' 36 | compile 'com.orhanobut:logger:1.15' 37 | compile 'com.android.support.constraint:constraint-layout:1.0.1' 38 | compile 'jp.wasabeef:recyclerview-animators:2.2.6' 39 | compile 'io.reactivex.rxjava2:rxandroid:2.0.1' 40 | compile 'io.reactivex.rxjava2:rxjava:2.0.1' 41 | testCompile 'junit:junit:4.12' 42 | } 43 | -------------------------------------------------------------------------------- /app/keep_in_main_dex.txt: -------------------------------------------------------------------------------- 1 | # you can copy the tinker keep rule at 2 | # build/intermediates/tinker_intermediates/tinker_multidexkeep.pro 3 | 4 | -keep class com.tencent.tinker.loader.** { 5 | *; 6 | } 7 | 8 | -keep class tinker.sample.android.app.SampleApplication { 9 | *; 10 | } 11 | 12 | -keep public class * implements com.tencent.tinker.loader.app.ApplicationLifeCycle { 13 | *; 14 | } 15 | 16 | -keep public class * extends com.tencent.tinker.loader.TinkerLoader { 17 | *; 18 | } 19 | 20 | -keep public class * extends com.tencent.tinker.loader.app.TinkerApplication { 21 | *; 22 | } 23 | 24 | # here, it is your own keep rules. 25 | # you must be careful that the class name you write won't be proguard 26 | # but the tinker class above is OK, we have already keep for you! 27 | -------------------------------------------------------------------------------- /app/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 /Applications/Android-SDK/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 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 34 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /app/src/main/java/com/allen/recyclerview/MainApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************* Copyright (c)*********************************\ 3 | ** 4 | ** (c) Copyright 2015, Allen, china, shanghai 5 | ** All Rights Reserved 6 | ** 7 | ** 8 | ** 9 | **-----------------------------------版本信息------------------------------------ 10 | ** 版 本: V0.1 11 | ** 12 | **------------------------------------------------------------------------------ 13 | ********************************End of Head************************************\ 14 | */ 15 | package com.allen.recyclerview; 16 | 17 | import android.app.Application; 18 | 19 | import com.orhanobut.logger.LogLevel; 20 | import com.orhanobut.logger.Logger; 21 | 22 | /** 23 | * 文 件 名: MainApplication 24 | * 创 建 人: Allen 25 | * 创建日期: 16/11/16 10:34 26 | * 邮 箱: AllenCoder@126.com 27 | * 修改时间: 28 | * 修改备注: 29 | */ 30 | public class MainApplication extends Application { 31 | 32 | 33 | @Override 34 | public void onCreate() { 35 | super.onCreate(); 36 | com.wanjian.sak.LayoutManager.init(this); 37 | Logger 38 | .init("MainApplication") // default PRETTYLOGGER or use just init() 39 | .methodCount(1) // default 2 40 | .hideThreadInfo() // default shown 41 | .logLevel(LogLevel.FULL) // default LogLevel.FULL 42 | .methodOffset(2) // default 0 43 | ; //default AndroidLogAdapter 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /app/src/main/java/com/allen/recyclerview/activity/CustomView.java: -------------------------------------------------------------------------------- 1 | package com.allen.recyclerview.activity; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | 6 | import com.allen.recyclerview.R; 7 | 8 | public class CustomView extends AppCompatActivity { 9 | 10 | @Override 11 | protected void onCreate(Bundle savedInstanceState) { 12 | super.onCreate(savedInstanceState); 13 | setContentView(R.layout.activity_custom_view); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /app/src/main/java/com/allen/recyclerview/activity/GooglePlayActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************* Copyright (c)*********************************\ 3 | ** 4 | ** (c) Copyright 2015, Allen, china, shanghai 5 | ** All Rights Reserved 6 | ** 7 | ** 8 | ** 9 | **-----------------------------------版本信息------------------------------------ 10 | ** 版 本: V0.1 11 | ** 12 | **------------------------------------------------------------------------------ 13 | ********************************End of Head************************************\ 14 | */ 15 | package com.allen.recyclerview.activity; 16 | 17 | import android.os.Bundle; 18 | import android.support.annotation.Nullable; 19 | import android.support.v7.app.AppCompatActivity; 20 | import android.support.v7.widget.LinearLayoutManager; 21 | import android.support.v7.widget.RecyclerView; 22 | import android.util.Log; 23 | import android.view.View; 24 | 25 | import com.allen.recyclerview.R; 26 | import com.allen.recyclerview.adapter.GooglePlayAdapter; 27 | import com.allen.recyclerview.data.DataServer; 28 | import com.chad.library.adapter.base.BaseQuickAdapter; 29 | 30 | /** 31 | * 文 件 名: GooglePlayActivity 32 | * 创 建 人: Allen 33 | * 创建日期: 16/12/29 10:28 34 | * 邮 箱: AllenCoder@126.com 35 | * 修改时间: 36 | * 修改备注: 37 | */ 38 | public class GooglePlayActivity extends AppCompatActivity { 39 | private RecyclerView mRootRecyclerviewRecyclerView; 40 | private String TAG="GooglePlayActivity"; 41 | 42 | @Override 43 | protected void onCreate(@Nullable final Bundle savedInstanceState) { 44 | super.onCreate(savedInstanceState); 45 | setContentView(R.layout.activity_recyclerview_nest); 46 | mRootRecyclerviewRecyclerView = (RecyclerView) findViewById(R.id.root_recyclerview); 47 | 48 | LinearLayoutManager layoutManager = new LinearLayoutManager(this,LinearLayoutManager.VERTICAL,false); 49 | mRootRecyclerviewRecyclerView.setLayoutManager(layoutManager); 50 | mRootRecyclerviewRecyclerView.setHasFixedSize(true); 51 | initAdapter(); 52 | } 53 | 54 | private void initAdapter() { 55 | GooglePlayAdapter mQuickAdapter = new GooglePlayAdapter(DataServer.getNews()); 56 | mQuickAdapter.openLoadAnimation(); 57 | mRootRecyclerviewRecyclerView.setAdapter(mQuickAdapter); 58 | mQuickAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() { 59 | @Override 60 | public void onItemClick(BaseQuickAdapter baseQuickAdapter, View view, int i) { 61 | Log.d(TAG, "onSimpleItemClick: "+"父层onItemChildClick收到点击事件"); 62 | } 63 | }); 64 | // mRootRecyclerviewRecyclerView.addOnItemTouchListener(new OnItemClickListener() { 65 | // @Override 66 | // public void onSimpleItemClick(final BaseQuickAdapter baseQuickAdapter, final View view, final int i) { 67 | // Log.d(TAG, "onSimpleItemClick: "+"父层item收到点击事件"); 68 | // } 69 | // 70 | // @Override 71 | // public void onItemChildClick(final BaseQuickAdapter adapter, final View view, final int position) { 72 | // super.onItemChildClick(adapter, view, position); 73 | // Log.d(TAG, "onSimpleItemClick: "+"父层onItemChildClick收到点击事件"); 74 | // } 75 | // } 76 | // ); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /app/src/main/java/com/allen/recyclerview/activity/HideActivity.java: -------------------------------------------------------------------------------- 1 | package com.allen.recyclerview.activity; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.support.v7.widget.LinearLayoutManager; 6 | import android.support.v7.widget.RecyclerView; 7 | import android.util.Log; 8 | import android.view.View; 9 | 10 | import com.allen.recyclerview.R; 11 | import com.allen.recyclerview.adapter.HideAdapter; 12 | import com.allen.recyclerview.data.DataServer; 13 | import com.allen.recyclerview.entry.MarryInfo; 14 | import com.chad.library.adapter.base.BaseQuickAdapter; 15 | import com.chad.library.adapter.base.listener.OnItemClickListener; 16 | 17 | import java.util.List; 18 | 19 | public class HideActivity extends AppCompatActivity { 20 | RecyclerView mRootRecyclerviewRecyclerView; 21 | @Override 22 | protected void onCreate(Bundle savedInstanceState) { 23 | super.onCreate(savedInstanceState); 24 | setContentView(R.layout.activity_hide); 25 | mRootRecyclerviewRecyclerView = (RecyclerView) findViewById(R.id.activity_hide); 26 | 27 | LinearLayoutManager layoutManager = new LinearLayoutManager(this); 28 | mRootRecyclerviewRecyclerView.setLayoutManager(layoutManager); 29 | mRootRecyclerviewRecyclerView.setHasFixedSize(true); 30 | initAdapter(); 31 | } 32 | 33 | private void initAdapter() { 34 | final List marray = DataServer.getMarray(10); 35 | final HideAdapter mQuickAdapter = new HideAdapter(marray); 36 | mQuickAdapter.openLoadAnimation(); 37 | mRootRecyclerviewRecyclerView.setAdapter(mQuickAdapter); 38 | 39 | Log.e("SimpleClickListener", "convert: 不重复按钮ID "+R.id.tv_unrepeat); 40 | Log.e("SimpleClickListener", "convert: 重复按钮ID "+R.id.tv_repeat); 41 | Log.e("SimpleClickListener", "convert: 有效按钮ID "+R.id.tv_valid); 42 | Log.e("SimpleClickListener", "convert: 无效按钮ID "+R.id.tv_invalid); 43 | mRootRecyclerviewRecyclerView.addOnItemTouchListener(new OnItemClickListener() { 44 | @Override 45 | public void onSimpleItemClick(final BaseQuickAdapter baseQuickAdapter, final View view, final int i) { 46 | Log.d(TAG, "onSimpleItemClick: "+"父层item收到点击事件"); 47 | } 48 | 49 | @Override 50 | public void onItemChildClick(final BaseQuickAdapter adapter, final View view, final int position) { 51 | super.onItemChildClick(adapter, view, position); 52 | switch (view.getId()){ 53 | case R.id.tv_repeat: 54 | Log.d(TAG, "onItemChildClick: "+"点击了重复按钮"); 55 | marray.get(position).isShow =false; 56 | break; 57 | case R.id.tv_unrepeat: 58 | Log.d(TAG, "onItemChildClick: "+"点击了不重复按钮"); 59 | marray.get(position).isShow =false; 60 | break; 61 | case R.id.tv_valid: 62 | Log.d(TAG, "onItemChildClick: "+"点击了有效按钮"); 63 | marray.get(position).isShow =true; 64 | break; 65 | case R.id.tv_invalid: 66 | Log.d(TAG, "onItemChildClick: "+"点击了无效按钮"); 67 | marray.get(position).isShow =true; 68 | break; 69 | } 70 | mQuickAdapter.notifyDataSetChanged(); 71 | } 72 | }); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /app/src/main/java/com/allen/recyclerview/activity/HorizontalAdjustActivity.java: -------------------------------------------------------------------------------- 1 | package com.allen.recyclerview.activity; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | import android.support.v7.widget.LinearLayoutManager; 6 | import android.support.v7.widget.RecyclerView; 7 | import android.view.MotionEvent; 8 | 9 | import com.allen.recyclerview.R; 10 | import com.allen.recyclerview.adapter.HorizationAdapter; 11 | 12 | /** 13 | * create by AllenCoder 14 | */ 15 | public class HorizontalAdjustActivity extends Activity { 16 | 17 | private HorizationAdapter horizationAdapter; 18 | private LinearLayoutManager layoutManager1; 19 | private LinearLayoutManager layoutManager2; 20 | private LinearLayoutManager layoutManager3; 21 | private RecyclerView recyclerview1; 22 | private RecyclerView recyclerview2; 23 | private RecyclerView recyclerview3; 24 | 25 | @Override 26 | protected void onCreate(Bundle savedInstanceState) { 27 | super.onCreate(savedInstanceState); 28 | setContentView(R.layout.activity_horizontal_adjust); 29 | initView(); 30 | 31 | layoutManager1 = new LinearLayoutManager(this); 32 | layoutManager1.setOrientation(LinearLayoutManager.HORIZONTAL); 33 | layoutManager2 = new LinearLayoutManager(this); 34 | layoutManager2.setOrientation(LinearLayoutManager.HORIZONTAL); 35 | layoutManager3 = new LinearLayoutManager(this); 36 | layoutManager3.setOrientation(LinearLayoutManager.HORIZONTAL); 37 | recyclerview1.setLayoutManager(layoutManager1); 38 | recyclerview2.setLayoutManager(layoutManager2); 39 | recyclerview3.setLayoutManager(layoutManager3); 40 | initAdapter(); 41 | } 42 | 43 | 44 | private void initAdapter() { 45 | horizationAdapter = new HorizationAdapter(this, 3); 46 | horizationAdapter.openLoadAnimation(); 47 | recyclerview1.setAdapter(horizationAdapter); 48 | horizationAdapter = new HorizationAdapter(this,5); 49 | recyclerview2.setAdapter(horizationAdapter); 50 | horizationAdapter = new HorizationAdapter(this, 7); 51 | recyclerview3.setAdapter(horizationAdapter); 52 | } 53 | 54 | 55 | @Override 56 | public boolean dispatchTouchEvent(MotionEvent ev) { 57 | return super.dispatchTouchEvent(ev); 58 | } 59 | 60 | private void initView() { 61 | recyclerview1 = (RecyclerView) findViewById(R.id.recyclerview1); 62 | recyclerview2 = (RecyclerView) findViewById(R.id.recyclerview2); 63 | recyclerview3 = (RecyclerView) findViewById(R.id.recyclerview3); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /app/src/main/java/com/allen/recyclerview/activity/ListActivity.java: -------------------------------------------------------------------------------- 1 | package com.allen.recyclerview.activity; 2 | 3 | import android.content.Intent; 4 | import android.net.Uri; 5 | import android.os.Bundle; 6 | import android.support.v7.app.AppCompatActivity; 7 | import android.util.Log; 8 | import android.view.LayoutInflater; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | import android.view.ViewParent; 12 | import android.widget.AdapterView; 13 | import android.widget.BaseAdapter; 14 | import android.widget.LinearLayout; 15 | import android.widget.ListView; 16 | import android.widget.TextView; 17 | 18 | import com.allen.recyclerview.R; 19 | import com.allen.recyclerview.data.DataServer; 20 | import com.allen.recyclerview.entry.MarryInfo; 21 | import com.orhanobut.logger.Logger; 22 | 23 | import java.util.ArrayList; 24 | import java.util.List; 25 | 26 | import static android.view.View.VISIBLE; 27 | 28 | public class ListActivity extends AppCompatActivity { 29 | private List news = new ArrayList<>(); 30 | private ListView listView; 31 | private List infoList; 32 | private String TAG = "ListActivity"; 33 | private TextView tv_name; 34 | private TextView tv_phone; 35 | private TextView tv_unrepeat; 36 | private TextView tv_repeat; 37 | private LinearLayout ly_a; 38 | private TextView tv_valid; 39 | private TextView tv_invalid; 40 | private LinearLayout ly_b; 41 | private LinearLayout ly; 42 | 43 | @Override 44 | protected void onCreate(Bundle savedInstanceState) { 45 | super.onCreate(savedInstanceState); 46 | setContentView(R.layout.activity_list); 47 | initView(); 48 | news.add("A"); 49 | news.add("B"); 50 | news.add("C"); 51 | news.add("A"); 52 | news.add("B"); 53 | news.add("D"); 54 | listView = (ListView) findViewById(R.id.list); 55 | infoList = DataServer.getMarray(10); 56 | listView.setAdapter(new CustomAdapter(infoList)); 57 | listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { 58 | @Override 59 | public void onItemClick(final AdapterView parent, final View view, final int position, final long id) { 60 | // view.setPressed(true); 61 | Log.d(TAG, "onItemClick: "); 62 | // view.findViewById(R.id.tv).setPressed(true); 63 | 64 | String movieurl="http://xxx.xxx.xx.xx:8080/play/test.mp4";//在线视频地址 65 | Intent intent = new Intent(Intent.ACTION_VIEW); 66 | String type = "video/mpeg";//视频类型 67 | Uri uri = Uri.parse(movieurl); 68 | intent.setDataAndType(uri, type); 69 | startActivity(intent); 70 | } 71 | }); 72 | 73 | 74 | 75 | 76 | // ly.setOnClickListener(new View.OnClickListener() { 77 | // @Override 78 | // public void onClick(final View v) { 79 | // Logger.d(TAG, "onResume: "+(isShown(ly_a))); 80 | // Logger.d(TAG, "onResume: "+(isShown(ly_a))); 81 | // Logger.d(TAG, "onResume: "+(isShown(tv_valid))); 82 | // Logger.d(TAG, "onResume: "+(tv_invalid.isShown())); 83 | // } 84 | // }); 85 | } 86 | 87 | @Override 88 | public void onWindowFocusChanged(final boolean hasFocus) { 89 | super.onWindowFocusChanged(hasFocus); 90 | if (hasFocus){ 91 | Logger.d(TAG, "onResume: "+(isShown(ly_a))); 92 | Logger.d(TAG, "onResume: "+(isShown(ly_a))); 93 | Logger.d(TAG, "onResume: "+(isShown(tv_valid))); 94 | Logger.d(TAG, "onResume: "+(tv_invalid.isShown())); 95 | } 96 | } 97 | 98 | @Override 99 | protected void onResume() { 100 | super.onResume(); 101 | Logger.d(TAG, "onCreate: "+(tv_unrepeat.getVisibility()== VISIBLE)); 102 | Logger.d(TAG, "onCreate: "+(tv_repeat.getVisibility()== VISIBLE)); 103 | Logger.d(TAG, "onCreate: "+(tv_valid.getVisibility()== VISIBLE)); 104 | Logger.d(TAG, "onCreate: "+(tv_invalid.getVisibility()== VISIBLE)); 105 | Logger.d(TAG, "onResume: "+(isShown(ly_a))); 106 | Logger.d(TAG, "onResume: "+(isShown(ly_a))); 107 | Logger.d(TAG, "onResume: "+(isShown(tv_valid))); 108 | Logger.d(TAG, "onResume: "+(tv_invalid.isShown())); 109 | } 110 | static final int VISIBILITY_MASK = 0x0000000C; 111 | public boolean isShown(View view) { 112 | View current = view; 113 | //noinspection ConstantConditions 114 | Logger.d(TAG, "isShown: ------------------"); 115 | do { 116 | if (view.getVisibility() != VISIBLE) { 117 | Logger.d(TAG, "isShown: view.getVisibility() != VISIBLE"+"不可见"); 118 | return false; 119 | } 120 | ViewParent parent = current.getParent(); 121 | if (parent == null) { 122 | Logger.d(TAG, "isShown: parent == null"+"不可见"); 123 | return false; // We are not attached to the view root 124 | } 125 | if (!(parent instanceof View)) { 126 | Logger.d(TAG, "isShown: "+"可见"); 127 | return true; 128 | } 129 | current = (View) parent; 130 | } while (current != null); 131 | Logger.d(TAG, "isShown: "+"不可见"); 132 | return false; 133 | } 134 | public boolean checkViewVisible(View view){ 135 | return view.getVisibility() == VISIBLE ; 136 | } 137 | 138 | private void initView() { 139 | tv_name = (TextView) findViewById(R.id.tv_name); 140 | tv_phone = (TextView) findViewById(R.id.tv_phone); 141 | tv_unrepeat = (TextView) findViewById(R.id.tv_unrepeat); 142 | tv_repeat = (TextView) findViewById(R.id.tv_repeat); 143 | ly_a = (LinearLayout) findViewById(R.id.ly_a); 144 | tv_valid = (TextView) findViewById(R.id.tv_valid); 145 | tv_invalid = (TextView) findViewById(R.id.tv_invalid); 146 | ly_b = (LinearLayout) findViewById(R.id.ly_b); 147 | ly = (LinearLayout) findViewById(R.id.ly); 148 | } 149 | 150 | 151 | public class CustomAdapter extends BaseAdapter implements View.OnClickListener { 152 | private List news; 153 | LayoutInflater layoutInflater = LayoutInflater.from(ListActivity.this); 154 | 155 | public CustomAdapter(final List news) { 156 | this.news = news; 157 | } 158 | 159 | @Override 160 | public int getCount() { 161 | return news.size(); 162 | } 163 | 164 | @Override 165 | public Object getItem(final int position) { 166 | return news.get(position); 167 | } 168 | 169 | @Override 170 | public long getItemId(final int position) { 171 | return position; 172 | } 173 | 174 | @Override 175 | public View getView(final int position, View convertView, final ViewGroup parent) { 176 | ViewHolder holder = null; 177 | if (convertView == null) { 178 | convertView = layoutInflater.inflate(R.layout.item_marray, null); 179 | } else { 180 | convertView.getTag(); 181 | } 182 | holder = new ViewHolder(convertView); 183 | holder.tv_name.setText(news.get(position).getName()); 184 | holder.tv_phone.setText(news.get(position).getPhone()); 185 | if (news.get(position).isShow) { 186 | holder.ly_a.setVisibility(VISIBLE); 187 | holder.ly_b.setVisibility(View.GONE); 188 | } else { 189 | holder.ly_a.setVisibility(View.GONE); 190 | holder.ly_b.setVisibility(VISIBLE); 191 | } 192 | final ViewHolder finalHolder = holder; 193 | // holder.tv_unrepeat.setOnClickListener(new View.OnClickListener() { 194 | // @Override 195 | // public void onClick(final View v) { 196 | // 197 | // Logger.e(TAG, "onClick: " + finalHolder.tv_unrepeat.getId()+"可见吗? " + "" + (finalHolder.tv_unrepeat.isShown())); 198 | // Logger.e(TAG, "onClick: " + finalHolder.tv_repeat.getId()+"可见吗? " + "" + (finalHolder.tv_repeat.isShown())); 199 | // Logger.e(TAG, "onClick: " + finalHolder.tv_invalid.getId()+"可见吗? " + "" + (finalHolder.tv_invalid.isShown())); 200 | // Logger.e(TAG, "onClick: " + finalHolder.tv_valid.getId() +"可见吗? "+ "" + (finalHolder.tv_valid.isShown())); 201 | // 202 | // infoList.get(position).isShow = false; 203 | // notifyDataSetChanged(); 204 | // } 205 | // }); 206 | // 207 | // holder.tv_repeat.setOnClickListener(new View.OnClickListener() { 208 | // @Override 209 | // public void onClick(final View v) { 210 | // 211 | // Logger.e(TAG, "onClick: " + finalHolder.tv_unrepeat.getId()+"可见吗? " + "" + (finalHolder.tv_unrepeat.isShown())); 212 | // Logger.e(TAG, "onClick: " + finalHolder.tv_repeat.getId()+"可见吗? " + "" + (finalHolder.tv_repeat.isShown())); 213 | // Logger.e(TAG, "onClick: " + finalHolder.tv_invalid.getId()+"可见吗? " + "" + (finalHolder.tv_invalid.isShown())); 214 | // Logger.e(TAG, "onClick: " + finalHolder.tv_valid.getId() +"可见吗? "+ "" + (finalHolder.tv_valid.isShown())); 215 | // 216 | // infoList.get(position).isShow = false; 217 | // notifyDataSetChanged(); 218 | // } 219 | // }); 220 | // holder.tv_valid.setOnClickListener(new View.OnClickListener() { 221 | // @Override 222 | // public void onClick(final View v) { 223 | // 224 | // Logger.e(TAG, "onClick: " + finalHolder.tv_unrepeat.getId()+"可见吗? " + "" + (finalHolder.tv_unrepeat.isShown())); 225 | // Logger.e(TAG, "onClick: " + finalHolder.tv_repeat.getId()+"可见吗? " + "" + (finalHolder.tv_repeat.isShown())); 226 | // Logger.e(TAG, "onClick: " + finalHolder.tv_invalid.getId()+"可见吗? " + "" + (finalHolder.tv_invalid.isShown())); 227 | // Logger.e(TAG, "onClick: " + finalHolder.tv_valid.getId() +"可见吗? "+ "" + (finalHolder.tv_valid.isShown())); 228 | // 229 | // infoList.get(position).isShow = true; 230 | // notifyDataSetChanged(); 231 | // } 232 | // }); 233 | // holder.tv_invalid.setOnClickListener(new View.OnClickListener() { 234 | // @Override 235 | // public void onClick(final View v) { 236 | // 237 | // Logger.e(TAG, "onClick: " + finalHolder.tv_unrepeat.getId()+"可见吗? " + "" + (finalHolder.tv_unrepeat.isShown())); 238 | // Logger.e(TAG, "onClick: " + finalHolder.tv_repeat.getId()+"可见吗? " + "" + (finalHolder.tv_repeat.isShown())); 239 | // Logger.e(TAG, "onClick: " + finalHolder.tv_invalid.getId()+"可见吗? " + "" + (finalHolder.tv_invalid.isShown())); 240 | // Logger.e(TAG, "onClick: " + finalHolder.tv_valid.getId() +"可见吗? "+ "" + (finalHolder.tv_valid.isShown())); 241 | // 242 | // infoList.get(position).isShow = true; 243 | // notifyDataSetChanged(); 244 | // } 245 | // }); 246 | 247 | 248 | return convertView; 249 | } 250 | 251 | @Override 252 | public void onClick(final View v) { 253 | 254 | Logger.e("onClick", "onClick: "); 255 | switch (v.getId()) { 256 | 257 | } 258 | } 259 | 260 | public class ViewHolder { 261 | public View rootView; 262 | public TextView tv_name; 263 | public TextView tv_phone; 264 | public TextView tv_unrepeat; 265 | public TextView tv_repeat; 266 | public LinearLayout ly_a; 267 | public TextView tv_valid; 268 | public TextView tv_invalid; 269 | public LinearLayout ly_b; 270 | 271 | public ViewHolder(View rootView) { 272 | this.rootView = rootView; 273 | this.tv_name = (TextView) rootView.findViewById(R.id.tv_name); 274 | this.tv_phone = (TextView) rootView.findViewById(R.id.tv_phone); 275 | this.tv_unrepeat = (TextView) rootView.findViewById(R.id.tv_unrepeat); 276 | this.tv_repeat = (TextView) rootView.findViewById(R.id.tv_repeat); 277 | this.ly_a = (LinearLayout) rootView.findViewById(R.id.ly_a); 278 | this.tv_valid = (TextView) rootView.findViewById(R.id.tv_valid); 279 | this.tv_invalid = (TextView) rootView.findViewById(R.id.tv_invalid); 280 | this.ly_b = (LinearLayout) rootView.findViewById(R.id.ly_b); 281 | } 282 | 283 | } 284 | } 285 | } 286 | -------------------------------------------------------------------------------- /app/src/main/java/com/allen/recyclerview/activity/LocalRefreshActivity.java: -------------------------------------------------------------------------------- 1 | package com.allen.recyclerview.activity; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.support.v7.widget.LinearLayoutManager; 6 | import android.support.v7.widget.RecyclerView; 7 | import android.util.Log; 8 | 9 | import com.allen.recyclerview.R; 10 | import com.allen.recyclerview.adapter.RefreshAdapter; 11 | import com.allen.recyclerview.data.DataServer; 12 | import com.allen.recyclerview.entry.News; 13 | 14 | import java.util.List; 15 | import java.util.concurrent.Callable; 16 | import java.util.concurrent.TimeUnit; 17 | 18 | import io.reactivex.Flowable; 19 | import io.reactivex.Observable; 20 | import io.reactivex.ObservableEmitter; 21 | import io.reactivex.ObservableOnSubscribe; 22 | import io.reactivex.android.schedulers.AndroidSchedulers; 23 | import io.reactivex.functions.Consumer; 24 | import io.reactivex.schedulers.Schedulers; 25 | 26 | public class LocalRefreshActivity extends AppCompatActivity { 27 | private RefreshAdapter adapter; 28 | private RecyclerView recyclerView; 29 | private String TAG ="LocalRefreshActivity"; 30 | 31 | @Override 32 | protected void onCreate(Bundle savedInstanceState) { 33 | super.onCreate(savedInstanceState); 34 | List list = DataServer.getNews(); 35 | adapter = new RefreshAdapter(list); 36 | setContentView(R.layout.activity_local_refresh); 37 | recyclerView = (RecyclerView) findViewById(R.id.recyclerview); 38 | recyclerView.setLayoutManager(new LinearLayoutManager(LocalRefreshActivity.this)); 39 | recyclerView.setAdapter(adapter); 40 | Observable.interval(1000,1000, TimeUnit.MILLISECONDS).create(new ObservableOnSubscribe() { 41 | @Override 42 | public void subscribe(ObservableEmitter e) throws Exception { 43 | Log.d(TAG, "subscribe: "); 44 | } 45 | 46 | 47 | 48 | 49 | }).observeOn(Schedulers.io()).subscribeOn(AndroidSchedulers.mainThread()); 50 | } 51 | public static void main(String[] args) { 52 | Flowable.just("Hello world").subscribe(new Consumer() { 53 | @Override 54 | public void accept(String s) throws Exception { 55 | System.out.println("s = " + s); } 56 | }); 57 | // Observable.interval(1000,1000, TimeUnit.MILLISECONDS).create(new ObservableOnSubscribe() { 58 | // @Override 59 | // public void subscribe(ObservableEmitter e) throws Exception { 60 | // System.out.println("s = " + e); 61 | // } 62 | // }); 63 | Observable.interval(2000,1000, TimeUnit.MILLISECONDS).subscribe(new Consumer() { 64 | @Override 65 | public void accept(Long aLong) throws Exception { 66 | System.out.println("aLong = " + aLong); 67 | } 68 | }); 69 | Flowable.fromCallable(new Callable() { 70 | @Override 71 | public String call() throws Exception { 72 | System.out.println("args = " ); 73 | return null; 74 | } 75 | }) 76 | .subscribeOn(Schedulers.io()) 77 | .observeOn(Schedulers.single()); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /app/src/main/java/com/allen/recyclerview/activity/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.allen.recyclerview.activity; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.support.v7.widget.LinearLayoutManager; 7 | import android.support.v7.widget.RecyclerView; 8 | import android.view.View; 9 | import android.widget.RelativeLayout; 10 | 11 | import com.allen.recyclerview.R; 12 | import com.allen.recyclerview.adapter.HomeAdapter; 13 | import com.allen.recyclerview.entry.Home; 14 | import com.chad.library.adapter.base.BaseQuickAdapter; 15 | 16 | import java.util.ArrayList; 17 | import java.util.List; 18 | 19 | public class MainActivity extends AppCompatActivity { 20 | private LinearLayoutManager layoutManager; 21 | protected RecyclerView recyclerview; 22 | protected RelativeLayout activityMain; 23 | private HomeAdapter homeAdapter; 24 | private List activityList; 25 | private String[] activityTitle = {"RecyclerView 滚动定位", "水平调整布局", "垂直调整布局","Listview对比测试","自定义View测试","GooglePlay Demo","显示隐藏","点击事件性能优化","网格处理计算器布局","局部刷新","旋转自定义测试"}; 26 | private Class[] ACTIVITY = {RecyclerClickItemActivity.class, HorizontalAdjustActivity.class, VerticalAdjustActivity.class,ListActivity.class,CustomView.class,GooglePlayActivity.class,HideActivity.class,OptimizeItemClickActivity.class,OptimizeItem2ClickActivity.class,LocalRefreshActivity.class,RotateActivity.class 27 | }; 28 | 29 | @Override 30 | protected void onCreate(Bundle savedInstanceState) { 31 | super.onCreate(savedInstanceState); 32 | super.setContentView(R.layout.activity_main); 33 | initData(); 34 | initView(); 35 | initAdapter(); 36 | recyclerview.setAdapter(homeAdapter); 37 | recyclerview.setLayoutManager(layoutManager); 38 | // recyclerview.addOnItemTouchListener(new OnItemClickListener() { 39 | // @Override 40 | // public void onSimpleItemClick(final BaseQuickAdapter baseQuickAdapter, final View view, final int position) { 41 | // Intent intent = new Intent(MainActivity.this, ACTIVITY[position]); 42 | // startActivity(intent); 43 | // } 44 | // }); 45 | homeAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() { 46 | @Override 47 | public void onItemClick(BaseQuickAdapter baseQuickAdapter, View view, int position) { 48 | Intent intent = new Intent(MainActivity.this, ACTIVITY[position]); 49 | startActivity(intent); 50 | } 51 | }); 52 | } 53 | 54 | private void initData() { 55 | activityList = new ArrayList<>(); 56 | for (int i = 0; i < activityTitle.length; i++) { 57 | Home home = new Home(activityTitle[i]); 58 | activityList.add(home); 59 | } 60 | 61 | 62 | } 63 | 64 | private void initAdapter() { 65 | homeAdapter = new HomeAdapter(activityList); 66 | layoutManager = new LinearLayoutManager(this); 67 | layoutManager.setOrientation(LinearLayoutManager.VERTICAL); 68 | 69 | } 70 | 71 | private void initView() { 72 | recyclerview = (RecyclerView) findViewById(R.id.recyclerview); 73 | activityMain = (RelativeLayout) findViewById(R.id.activity_main); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /app/src/main/java/com/allen/recyclerview/activity/OptimizeItem2ClickActivity.java: -------------------------------------------------------------------------------- 1 | package com.allen.recyclerview.activity; 2 | 3 | import android.os.Bundle; 4 | import android.support.design.widget.FloatingActionButton; 5 | import android.support.design.widget.Snackbar; 6 | import android.support.v7.app.AppCompatActivity; 7 | import android.support.v7.widget.GridLayoutManager; 8 | import android.support.v7.widget.RecyclerView; 9 | import android.support.v7.widget.Toolbar; 10 | import android.view.View; 11 | import android.widget.Toast; 12 | 13 | import com.allen.recyclerview.R; 14 | import com.allen.recyclerview.adapter.OptimeizeClickAdapter; 15 | import com.chad.library.adapter.base.BaseQuickAdapter; 16 | 17 | public class OptimizeItem2ClickActivity extends AppCompatActivity { 18 | private RecyclerView mRecyclerView; 19 | private OptimeizeClickAdapter mQuickAdapter; 20 | private static final int PAGE_SIZE = 100; 21 | @Override 22 | protected void onCreate(Bundle savedInstanceState) { 23 | super.onCreate(savedInstanceState); 24 | setContentView(R.layout.activity_optimize_item_click); 25 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 26 | setSupportActionBar(toolbar); 27 | 28 | FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); 29 | fab.setOnClickListener(new View.OnClickListener() { 30 | @Override 31 | public void onClick(View view) { 32 | Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) 33 | .setAction("Action", null).show(); 34 | } 35 | }); 36 | mRecyclerView = (RecyclerView) findViewById(R.id.list); 37 | GridLayoutManager layoutManager = new GridLayoutManager(this,4); 38 | mRecyclerView.setLayoutManager(layoutManager); 39 | initAdapter(); 40 | 41 | // /** 42 | // * Item clcik 43 | // */ 44 | // 45 | // mRecyclerView.addOnItemTouchListener(new OnItemClickListener() { 46 | // 47 | // @Override 48 | // public void onSimpleItemClick(BaseQuickAdapter adapter, View view, int position) { 49 | // } 50 | // 51 | // @Override 52 | // public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) { 53 | // Logger.d("当前时间 "+System.currentTimeMillis()); 54 | // super.onItemChildClick(adapter, view, position); 55 | // switch (view.getId()) { 56 | // 57 | // default: 58 | // break; 59 | // } 60 | // } 61 | // 62 | // 63 | // @Override 64 | // public void onItemLongClick(BaseQuickAdapter adapter, View view, int position) { 65 | // super.onItemLongClick(adapter, view, position); 66 | // 67 | // } 68 | // 69 | // @Override 70 | // public void onItemChildLongClick(BaseQuickAdapter adapter, View view, int position) { 71 | // super.onItemChildLongClick(adapter, view, position); 72 | // 73 | // } 74 | // }); 75 | } 76 | 77 | private void initAdapter() { 78 | mQuickAdapter = new OptimeizeClickAdapter(PAGE_SIZE); 79 | mQuickAdapter.openLoadAnimation(); 80 | mQuickAdapter.notifyItemChanged(1,1); 81 | mRecyclerView.setAdapter(mQuickAdapter); 82 | mQuickAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() { 83 | @Override 84 | public void onItemClick(BaseQuickAdapter baseQuickAdapter, View view, int i) { 85 | Toast.makeText(OptimizeItem2ClickActivity.this,"onItemClick",Toast.LENGTH_SHORT).show(); 86 | } 87 | }); 88 | mQuickAdapter.setOnItemLongClickListener(new BaseQuickAdapter.OnItemLongClickListener() { 89 | @Override 90 | public boolean onItemLongClick(BaseQuickAdapter baseQuickAdapter, View view, int i) { 91 | Toast.makeText(OptimizeItem2ClickActivity.this,"onItemLongClick",Toast.LENGTH_SHORT).show(); 92 | return true; 93 | } 94 | }); 95 | mQuickAdapter.setOnItemChildLongClickListener(new BaseQuickAdapter.OnItemChildLongClickListener() { 96 | @Override 97 | public boolean onItemChildLongClick(BaseQuickAdapter baseQuickAdapter, View view, int i) { 98 | Toast.makeText(OptimizeItem2ClickActivity.this,"onItemChildLongClick",Toast.LENGTH_SHORT).show(); 99 | return true; 100 | } 101 | }); 102 | mQuickAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() { 103 | @Override 104 | public void onItemChildClick(BaseQuickAdapter baseQuickAdapter, View view, int i) { 105 | Toast.makeText(OptimizeItem2ClickActivity.this,"onItemChildClick",Toast.LENGTH_SHORT).show(); 106 | } 107 | }); 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /app/src/main/java/com/allen/recyclerview/activity/OptimizeItemClickActivity.java: -------------------------------------------------------------------------------- 1 | package com.allen.recyclerview.activity; 2 | 3 | import android.os.Bundle; 4 | import android.support.design.widget.FloatingActionButton; 5 | import android.support.design.widget.Snackbar; 6 | import android.support.v7.app.AppCompatActivity; 7 | import android.support.v7.widget.LinearLayoutManager; 8 | import android.support.v7.widget.RecyclerView; 9 | import android.support.v7.widget.Toolbar; 10 | import android.view.View; 11 | 12 | import com.allen.recyclerview.R; 13 | import com.allen.recyclerview.adapter.OptimeizeClickAdapter; 14 | import com.chad.library.adapter.base.BaseQuickAdapter; 15 | import com.chad.library.adapter.base.listener.OnItemClickListener; 16 | import com.orhanobut.logger.Logger; 17 | 18 | public class OptimizeItemClickActivity extends AppCompatActivity { 19 | private RecyclerView mRecyclerView; 20 | private OptimeizeClickAdapter mQuickAdapter; 21 | private static final int PAGE_SIZE = 100; 22 | @Override 23 | protected void onCreate(Bundle savedInstanceState) { 24 | super.onCreate(savedInstanceState); 25 | setContentView(R.layout.activity_optimize_item_click); 26 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 27 | setSupportActionBar(toolbar); 28 | 29 | FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); 30 | fab.setOnClickListener(new View.OnClickListener() { 31 | @Override 32 | public void onClick(View view) { 33 | Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) 34 | .setAction("Action", null).show(); 35 | } 36 | }); 37 | mRecyclerView = (RecyclerView) findViewById(R.id.list); 38 | LinearLayoutManager layoutManager = new LinearLayoutManager(this); 39 | mRecyclerView.setLayoutManager(layoutManager); 40 | initAdapter(); 41 | 42 | // /** 43 | // * Item clcik 44 | // */ 45 | // 46 | mRecyclerView.addOnItemTouchListener(new OnItemClickListener() { 47 | 48 | @Override 49 | public void onSimpleItemClick(BaseQuickAdapter adapter, View view, int position) { 50 | } 51 | 52 | @Override 53 | public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) { 54 | Logger.d("当前时间 "+System.currentTimeMillis()); 55 | super.onItemChildClick(adapter, view, position); 56 | switch (view.getId()) { 57 | 58 | default: 59 | break; 60 | } 61 | } 62 | 63 | 64 | @Override 65 | public void onItemLongClick(BaseQuickAdapter adapter, View view, int position) { 66 | super.onItemLongClick(adapter, view, position); 67 | 68 | } 69 | 70 | @Override 71 | public void onItemChildLongClick(BaseQuickAdapter adapter, View view, int position) { 72 | super.onItemChildLongClick(adapter, view, position); 73 | 74 | } 75 | }); 76 | } 77 | 78 | private void initAdapter() { 79 | mQuickAdapter = new OptimeizeClickAdapter(PAGE_SIZE); 80 | mQuickAdapter.openLoadAnimation(); 81 | mRecyclerView.setAdapter(mQuickAdapter); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /app/src/main/java/com/allen/recyclerview/activity/RecyclerClickItemActivity.java: -------------------------------------------------------------------------------- 1 | package com.allen.recyclerview.activity; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | import android.support.v7.widget.LinearLayoutManager; 6 | import android.support.v7.widget.RecyclerView; 7 | import android.text.TextUtils; 8 | import android.view.MotionEvent; 9 | import android.view.View; 10 | import android.widget.Button; 11 | import android.widget.EditText; 12 | import android.widget.Toast; 13 | 14 | import com.allen.recyclerview.R; 15 | import com.allen.recyclerview.adapter.QuickClickAdapter; 16 | import com.chad.library.adapter.base.BaseQuickAdapter; 17 | import com.chad.library.adapter.base.listener.OnItemClickListener; 18 | 19 | /** 20 | * create by AllenCoder 21 | */ 22 | public class RecyclerClickItemActivity extends Activity { 23 | 24 | private RecyclerView mRecyclerView; 25 | private QuickClickAdapter mQuickAdapter; 26 | private static final int PAGE_SIZE = 100; 27 | private static String TAG = "RecyclerClickItemActivity"; 28 | private EditText etnum; 29 | private Button btnGo; 30 | private LinearLayoutManager layoutManager; 31 | @Override 32 | protected void onCreate(Bundle savedInstanceState) { 33 | super.onCreate(savedInstanceState); 34 | setContentView(R.layout.activity_recycler_click); 35 | this.btnGo = (Button) findViewById(R.id.btn_go); 36 | this.etnum = (EditText) findViewById(R.id.et_num); 37 | mRecyclerView = (RecyclerView) findViewById(R.id.list); 38 | layoutManager = new LinearLayoutManager(this); 39 | mRecyclerView.setLayoutManager(layoutManager); 40 | initAdapter(); 41 | 42 | // /** 43 | // * Item clcik 44 | // */ 45 | // 46 | mRecyclerView.addOnItemTouchListener(new OnItemClickListener() { 47 | 48 | @Override 49 | public void onSimpleItemClick(BaseQuickAdapter adapter, View view, int position) { 50 | Toast.makeText(RecyclerClickItemActivity.this, "" + Integer.toString(position), Toast.LENGTH_SHORT).show(); 51 | } 52 | 53 | @Override 54 | public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) { 55 | super.onItemChildClick(adapter, view, position); 56 | switch (view.getId()) { 57 | case R.id.tweetAvatar: 58 | Toast.makeText(RecyclerClickItemActivity.this, "The " + Integer.toString(position)+" tweetAvatar is clicked", Toast.LENGTH_SHORT).show(); 59 | break; 60 | case R.id.tweetName: 61 | Toast.makeText(RecyclerClickItemActivity.this, "The " + Integer.toString(position)+" tweetName is clicked", Toast.LENGTH_SHORT).show(); 62 | break; 63 | default: 64 | break; 65 | } 66 | } 67 | 68 | 69 | @Override 70 | public void onItemLongClick(BaseQuickAdapter adapter, View view, int position) { 71 | super.onItemLongClick(adapter, view, position); 72 | Toast.makeText(RecyclerClickItemActivity.this,"The " + Integer.toString(position)+ " Item is LongClick ", Toast.LENGTH_SHORT).show(); 73 | 74 | } 75 | 76 | @Override 77 | public void onItemChildLongClick(BaseQuickAdapter adapter, View view, int position) { 78 | super.onItemChildLongClick(adapter, view, position); 79 | Toast.makeText(RecyclerClickItemActivity.this, "The "+ Integer.toString(position)+" view itemchild " + "is LongClick " + Integer.toString(position), Toast.LENGTH_SHORT).show(); 80 | 81 | } 82 | }); 83 | btnGo.setOnClickListener(new View.OnClickListener() { 84 | @Override 85 | public void onClick(final View v) { 86 | if (!TextUtils.isEmpty(etnum.getText().toString())){ 87 | layoutManager.scrollToPositionWithOffset(Integer.valueOf(etnum.getText().toString()),0); 88 | layoutManager.setStackFromEnd(true); 89 | } 90 | } 91 | }); 92 | } 93 | 94 | 95 | private void initAdapter() { 96 | mQuickAdapter = new QuickClickAdapter(PAGE_SIZE); 97 | mQuickAdapter.openLoadAnimation(); 98 | mRecyclerView.setAdapter(mQuickAdapter); 99 | } 100 | 101 | 102 | @Override 103 | public boolean dispatchTouchEvent(MotionEvent ev) { 104 | return super.dispatchTouchEvent(ev); 105 | } 106 | 107 | } 108 | -------------------------------------------------------------------------------- /app/src/main/java/com/allen/recyclerview/activity/RotateActivity.java: -------------------------------------------------------------------------------- 1 | package com.allen.recyclerview.activity; 2 | 3 | import android.animation.Animator; 4 | import android.animation.ValueAnimator; 5 | import android.graphics.Path; 6 | import android.graphics.PathMeasure; 7 | import android.graphics.PixelFormat; 8 | import android.graphics.RectF; 9 | import android.os.Bundle; 10 | import android.support.v7.app.AppCompatActivity; 11 | import android.view.Gravity; 12 | import android.view.View; 13 | import android.view.WindowManager; 14 | import android.widget.ImageView; 15 | 16 | import com.allen.recyclerview.R; 17 | 18 | public class RotateActivity extends AppCompatActivity implements View.OnClickListener { 19 | 20 | private ImageView mImageView; 21 | 22 | @Override 23 | protected void onCreate(Bundle savedInstanceState) { 24 | super.onCreate(savedInstanceState); 25 | setContentView(R.layout.activity_rotate); 26 | initView(); 27 | } 28 | 29 | private void initView() { 30 | mImageView = (ImageView) findViewById(R.id.imageView); 31 | mImageView.setOnClickListener(this); 32 | } 33 | 34 | @Override 35 | public void onClick(View v) { 36 | switch (v.getId()) { 37 | case R.id.imageView: 38 | final ImageView moveImg = new ImageView(this); 39 | moveImg.setImageResource(R.mipmap.ic_launcher); 40 | ImageView imageView = (ImageView) v; 41 | WindowManager wm = getWindowManager(); 42 | final WindowManager.LayoutParams lp = new WindowManager.LayoutParams(WindowManager.LayoutParams.TYPE_TOAST); 43 | lp.width = imageView.getWidth(); 44 | lp.height = imageView.getHeight(); 45 | lp.format = PixelFormat.TRANSLUCENT; 46 | lp.gravity = Gravity.LEFT | Gravity.TOP; 47 | int fromX = (int) moveImg.getX(); 48 | int fromY = (int) moveImg.getY(); 49 | lp.x = fromX; 50 | lp.y = fromY - imageView.getHeight(); 51 | 52 | imageView.setPivotX(lp.width / 2); 53 | imageView.setPivotY(lp.height / 2); 54 | 55 | try { 56 | wm.addView(moveImg, lp); 57 | } catch (Exception e) { 58 | return; 59 | } 60 | 61 | Path path = getAnimMovePath(v.getX(),v.getY(),100,100); 62 | final PathMeasure pm = new PathMeasure(path, false); 63 | 64 | final float totalLen = pm.getLength(); 65 | ValueAnimator animator = ValueAnimator.ofFloat(0, totalLen) 66 | .setDuration(2000); 67 | animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 68 | @Override 69 | public void onAnimationUpdate(ValueAnimator animation) { 70 | float curLen = (float) animation.getAnimatedValue(); 71 | 72 | moveImg.setRotation(3000 * (1 - curLen / totalLen)); 73 | 74 | float[] curPos = new float[2]; 75 | pm.getPosTan(curLen, curPos, null); 76 | lp.x = (int) curPos[0]; 77 | lp.y = (int) curPos[1]; 78 | 79 | getWindowManager().updateViewLayout(moveImg, lp); 80 | } 81 | }); 82 | animator.addListener(new Animator.AnimatorListener() { 83 | @Override 84 | public void onAnimationStart(Animator animation) { 85 | 86 | } 87 | 88 | @Override 89 | public void onAnimationEnd(Animator animation) { 90 | try { 91 | getWindowManager().removeView(moveImg); 92 | } catch (Exception e) { 93 | // null 94 | } 95 | } 96 | 97 | @Override 98 | public void onAnimationCancel(Animator animation) { 99 | onAnimationEnd(animation); 100 | } 101 | 102 | @Override 103 | public void onAnimationRepeat(Animator animation) { 104 | 105 | } 106 | 107 | }); 108 | animator.start(); 109 | break; 110 | } 111 | } 112 | /** 113 | * 根据开始和结束点获取移动路径 114 | *

115 | * 让起点和终点落在一个圆上,取起点和终点所在一段圆弧作为路径! 116 | * 117 | * @return 移动路径 118 | */ 119 | private Path getAnimMovePath(float x1, float y1, int x2, int y2) { 120 | Path path = new Path(); 121 | 122 | // 起点和结束点中点 123 | float x0 = (x1 + x2) / 2f; 124 | float y0 = (y1 + y2) / 2f; 125 | // 圆半径,暂定为两点距离 126 | int r = (int) Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); 127 | // 起点和结束点连线的垂线斜率 128 | float k = -(float) (x1 - x2) / (y1 - y2); 129 | 130 | // 根据下边公式求圆心 131 | // cy = y0 + k * (cx - x0); 132 | // (cy - y0)^2 + (cx - x0)^2 + (r / 2)^2= r^2 133 | float cx0 = (float) (x0 + Math.sqrt(3) / 2 * r / Math.sqrt(k * k + 1)); // 第一个圆心X坐标 134 | float cx1 = (float) (x0 - Math.sqrt(3) / 2 * r / Math.sqrt(k * k + 1)); // 第二个圆心X坐标 135 | 136 | float cx = k < 0 ? cx1 : cx0; 137 | float cy = y0 + k * (cx - x0); 138 | 139 | float startAngle = (float) Math.toDegrees(Math.atan((y1 - cy) / (x1 - cx))); 140 | float toAngle = (float) Math.toDegrees(Math.atan((y2 - cy) / (x2 - cx))); 141 | 142 | if (k < 0) { 143 | startAngle += 360; 144 | toAngle += 360; 145 | 146 | if (toAngle > startAngle) { 147 | toAngle -= 180; 148 | } 149 | } else { 150 | startAngle += 180; 151 | toAngle += 180; 152 | } 153 | 154 | RectF rectF = new RectF(cx - r, cy - r, cx + r, cy + r); 155 | path.addArc(rectF, startAngle, toAngle - startAngle); 156 | return path; 157 | } 158 | } 159 | -------------------------------------------------------------------------------- /app/src/main/java/com/allen/recyclerview/activity/TestActivity.java: -------------------------------------------------------------------------------- 1 | package com.allen.recyclerview.activity; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.view.MotionEvent; 6 | 7 | import com.allen.recyclerview.R; 8 | import com.allen.recyclerview.view.ScrollByView; 9 | 10 | public class TestActivity extends AppCompatActivity { 11 | 12 | ScrollByView mScrollView; 13 | 14 | @Override 15 | protected void onCreate(Bundle savedInstanceState) { 16 | super.onCreate(savedInstanceState); 17 | setContentView(R.layout.activity_test); 18 | mScrollView = (ScrollByView) findViewById(R.id.scrollView); 19 | 20 | } 21 | 22 | @Override 23 | public boolean onTouchEvent(MotionEvent event) { 24 | mScrollView.onTouchEvent(event); 25 | return super.onTouchEvent(event); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /app/src/main/java/com/allen/recyclerview/activity/VerticalAdjustActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************* Copyright (c)*********************************\ 3 | ** 4 | ** (c) Copyright 2015, Allen, china, shanghai 5 | ** All Rights Reserved 6 | ** 7 | ** 8 | ** 9 | **-----------------------------------版本信息------------------------------------ 10 | ** 版 本: V0.1 11 | ** 12 | **------------------------------------------------------------------------------ 13 | ********************************End of Head************************************\ 14 | */ 15 | package com.allen.recyclerview.activity; 16 | 17 | import android.app.Activity; 18 | import android.os.Bundle; 19 | import android.support.v7.widget.LinearLayoutManager; 20 | import android.support.v7.widget.RecyclerView; 21 | import android.text.TextUtils; 22 | import android.view.MotionEvent; 23 | import android.view.View; 24 | import android.widget.Button; 25 | import android.widget.EditText; 26 | import android.widget.Toast; 27 | 28 | import com.allen.recyclerview.R; 29 | import com.allen.recyclerview.adapter.QuickClickAdapter; 30 | import com.chad.library.adapter.base.BaseQuickAdapter; 31 | import com.chad.library.adapter.base.listener.OnItemClickListener; 32 | 33 | /** 34 | * 文 件 名: VerticalAdjustActivity 35 | * 创 建 人: Allen 36 | * 创建日期: 16/10/29 13:28 37 | * 邮 箱: AllenCoder@126.com 38 | * 修改时间: 39 | * 修改备注: 40 | */ 41 | public class VerticalAdjustActivity extends Activity { 42 | private RecyclerView mRecyclerView; 43 | private QuickClickAdapter mQuickAdapter; 44 | private static final int PAGE_SIZE = 100; 45 | private static String TAG = "RecyclerClickItemActivity"; 46 | private EditText etnum; 47 | private Button btnGo; 48 | private LinearLayoutManager layoutManager; 49 | 50 | @Override 51 | protected void onCreate(Bundle savedInstanceState) { 52 | super.onCreate(savedInstanceState); 53 | setContentView(R.layout.activity_recycler_click); 54 | this.btnGo = (Button) findViewById(R.id.btn_go); 55 | this.etnum = (EditText) findViewById(R.id.et_num); 56 | mRecyclerView = (RecyclerView) findViewById(R.id.list); 57 | layoutManager = new LinearLayoutManager(this); 58 | mRecyclerView.setLayoutManager(layoutManager); 59 | initAdapter(); 60 | 61 | // /** 62 | // * Item clcik 63 | // */ 64 | // 65 | mRecyclerView.addOnItemTouchListener(new OnItemClickListener() { 66 | 67 | @Override 68 | public void onSimpleItemClick(BaseQuickAdapter adapter, View view, int position) { 69 | Toast.makeText(VerticalAdjustActivity.this, "" + Integer.toString(position), Toast.LENGTH_SHORT).show(); 70 | } 71 | 72 | 73 | }); 74 | btnGo.setOnClickListener(new View.OnClickListener() { 75 | @Override 76 | public void onClick(final View v) { 77 | if (!TextUtils.isEmpty(etnum.getText().toString())) { 78 | layoutManager.scrollToPositionWithOffset(Integer.valueOf(etnum.getText().toString()), 0); 79 | layoutManager.setStackFromEnd(true); 80 | } 81 | } 82 | }); 83 | } 84 | 85 | 86 | private void initAdapter() { 87 | mQuickAdapter = new QuickClickAdapter(PAGE_SIZE); 88 | mQuickAdapter.openLoadAnimation(); 89 | mRecyclerView.setAdapter(mQuickAdapter); 90 | } 91 | 92 | 93 | @Override 94 | public boolean dispatchTouchEvent(MotionEvent ev) { 95 | return super.dispatchTouchEvent(ev); 96 | } 97 | 98 | 99 | } 100 | -------------------------------------------------------------------------------- /app/src/main/java/com/allen/recyclerview/adapter/GooglePlayAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************* Copyright (c)*********************************\ 3 | ** 4 | ** (c) Copyright 2015, Allen, china, shanghai 5 | ** All Rights Reserved 6 | ** 7 | ** 8 | ** 9 | **-----------------------------------版本信息------------------------------------ 10 | ** 版 本: V0.1 11 | ** 12 | **------------------------------------------------------------------------------ 13 | ********************************End of Head************************************\ 14 | */ 15 | package com.allen.recyclerview.adapter; 16 | 17 | import android.support.v7.widget.LinearLayoutManager; 18 | import android.support.v7.widget.RecyclerView; 19 | import android.util.Log; 20 | import android.view.View; 21 | 22 | import com.allen.recyclerview.R; 23 | import com.allen.recyclerview.data.DataServer; 24 | import com.allen.recyclerview.entry.MarryInfo; 25 | import com.allen.recyclerview.entry.News; 26 | import com.chad.library.adapter.base.BaseQuickAdapter; 27 | import com.chad.library.adapter.base.BaseViewHolder; 28 | 29 | import java.util.List; 30 | 31 | /** 32 | * 文 件 名: GooglePlayAdapter 33 | * 创 建 人: Allen 34 | * 创建日期: 16/12/29 10:31 35 | * 邮 箱: AllenCoder@126.com 36 | * 修改时间: 37 | * 修改备注: 38 | */ 39 | public class GooglePlayAdapter extends BaseQuickAdapter implements BaseQuickAdapter.OnItemChildClickListener, BaseQuickAdapter.OnItemClickListener { 40 | public GooglePlayAdapter(final List data) { 41 | super(R.layout.item_googleplay,data); 42 | } 43 | 44 | @Override 45 | protected void convert(final BaseViewHolder baseViewHolder, final News news) { 46 | final RecyclerView recyclerView = (RecyclerView) baseViewHolder.getView(R.id.item_recyclerview); 47 | recyclerView.setLayoutManager(new LinearLayoutManager(baseViewHolder.getConvertView().getContext(),LinearLayoutManager.VERTICAL,false)); 48 | recyclerView.setHasFixedSize(true); 49 | // HorizationAdapter mQuickAdapter = new HorizationAdapter(baseViewHolder.getConvertView().getContext(),5, (int) (Math.random()*10)); 50 | final List marray = DataServer.getMarray(10); 51 | final HideAdapter mQuickAdapter = new HideAdapter(marray); 52 | mQuickAdapter.setOnItemClickListener(this); 53 | mQuickAdapter.setOnItemChildClickListener(this); 54 | recyclerView.setAdapter(mQuickAdapter); 55 | baseViewHolder.addOnClickListener(R.id.item_recyclerview); 56 | // recyclerView.addOnItemTouchListener(listener); 57 | } 58 | 59 | @Override 60 | public void onItemChildClick(BaseQuickAdapter baseQuickAdapter, View view, int i) { 61 | Log.e(TAG, "嵌套层收到点击事件: "+"点击了-次"); 62 | } 63 | 64 | @Override 65 | public void onItemClick(BaseQuickAdapter baseQuickAdapter, View view, int i) { 66 | Log.e(TAG, "嵌套层ItemChild点击事件: "+"点击了-次"); 67 | 68 | 69 | 70 | } 71 | // final OnItemClickListener listener = new OnItemClickListener() { 72 | // @Override 73 | // public void onSimpleItemClick(final BaseQuickAdapter baseQuickAdapter, final View view, final int i) { 74 | // Log.e(TAG, "嵌套层收到点击事件: "+"点击了-次"); 75 | // } 76 | // 77 | // @Override 78 | // public void onItemChildClick(final BaseQuickAdapter adapter, final View view, final int position) { 79 | // super.onItemChildClick(adapter, view, position); 80 | // Log.e(TAG, "嵌套层ItemChild点击事件: "+"点击了-次"); 81 | // } 82 | // }; 83 | } 84 | -------------------------------------------------------------------------------- /app/src/main/java/com/allen/recyclerview/adapter/GooglePlayItemAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************* Copyright (c)*********************************\ 3 | ** 4 | ** (c) Copyright 2015, Allen, china, shanghai 5 | ** All Rights Reserved 6 | ** 7 | ** 8 | ** 9 | **-----------------------------------版本信息------------------------------------ 10 | ** 版 本: V0.1 11 | ** 12 | **------------------------------------------------------------------------------ 13 | ********************************End of Head************************************\ 14 | */ 15 | package com.allen.recyclerview.adapter; 16 | 17 | import android.support.v7.widget.LinearLayoutManager; 18 | import android.support.v7.widget.RecyclerView; 19 | 20 | import com.allen.recyclerview.R; 21 | import com.allen.recyclerview.data.DataServer; 22 | import com.allen.recyclerview.entry.News; 23 | import com.chad.library.adapter.base.BaseQuickAdapter; 24 | import com.chad.library.adapter.base.BaseViewHolder; 25 | 26 | import java.util.List; 27 | 28 | /** 29 | * 文 件 名: GooglePlayItemAdapter 30 | * 创 建 人: Allen 31 | * 创建日期: 16/12/29 10:50 32 | * 邮 箱: AllenCoder@126.com 33 | * 修改时间: 34 | * 修改备注: 35 | */ 36 | public class GooglePlayItemAdapter extends BaseQuickAdapter { 37 | public GooglePlayItemAdapter(final List data) { 38 | super(R.layout.item_googleplay,data); 39 | } 40 | 41 | @Override 42 | protected void convert(final BaseViewHolder baseViewHolder, final News news) { 43 | final RecyclerView recyclerView = (RecyclerView) baseViewHolder.getView(R.id.item_recyclerview); 44 | recyclerView.setLayoutManager(new LinearLayoutManager(baseViewHolder.getConvertView().getContext(),LinearLayoutManager.HORIZONTAL,false)); 45 | recyclerView.setHasFixedSize(true); 46 | GooglePlayAdapter mQuickAdapter = new GooglePlayAdapter(DataServer.getNews()); 47 | recyclerView.setAdapter(mQuickAdapter); 48 | } 49 | private void initAdapter() { 50 | 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /app/src/main/java/com/allen/recyclerview/adapter/HideAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************* Copyright (c)*********************************\ 3 | ** 4 | ** (c) Copyright 2015, Allen, china, shanghai 5 | ** All Rights Reserved 6 | ** 7 | ** 8 | ** 9 | **-----------------------------------版本信息------------------------------------ 10 | ** 版 本: V0.1 11 | ** 12 | **------------------------------------------------------------------------------ 13 | ********************************End of Head************************************\ 14 | */ 15 | package com.allen.recyclerview.adapter; 16 | 17 | import com.allen.recyclerview.R; 18 | import com.allen.recyclerview.entry.MarryInfo; 19 | import com.chad.library.adapter.base.BaseQuickAdapter; 20 | import com.chad.library.adapter.base.BaseViewHolder; 21 | 22 | import java.util.List; 23 | 24 | /** 25 | * 文 件 名: HideAdapter 26 | * 创 建 人: Allen 27 | * 创建日期: 17/1/6 22:41 28 | * 邮 箱: AllenCoder@126.com 29 | * 修改时间: 30 | * 修改备注: 31 | */ 32 | public class HideAdapter extends BaseQuickAdapter { 33 | public HideAdapter(final List data) { 34 | super(R.layout.item_marray, data); 35 | } 36 | 37 | @Override 38 | protected void convert(final BaseViewHolder helper, final MarryInfo item) { 39 | helper 40 | .addOnClickListener(R.id.tv_unrepeat). 41 | addOnClickListener(R.id.tv_repeat). 42 | addOnClickListener(R.id.tv_valid). 43 | addOnClickListener(R.id.tv_invalid) 44 | // .setVisible(R.id.ly_a, item.isShow) 45 | // .setVisible(R.id.ly_b, !item.isShow) 46 | // .setVisible(R.id.tv_unrepeat, item.isShow) 47 | // .setVisible(R.id.tv_repeat, item.isShow) 48 | // .setVisible(R.id.tv_valid, !item.isShow) 49 | // .setVisible(R.id.tv_invalid, !item.isShow) 50 | .setText(R.id.tv_name, item.getName()) 51 | .setText(R.id.tv_phone, item.getPhone()); 52 | 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /app/src/main/java/com/allen/recyclerview/adapter/HomeAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************* Copyright (c)*********************************\ 3 | ** 4 | ** (c) Copyright 2015, Allen, china, shanghai 5 | ** All Rights Reserved 6 | ** 7 | ** 8 | ** 9 | **-----------------------------------版本信息------------------------------------ 10 | ** 版 本: V0.1 11 | ** 12 | **------------------------------------------------------------------------------ 13 | ********************************End of Head************************************\ 14 | */ 15 | package com.allen.recyclerview.adapter; 16 | 17 | import com.allen.recyclerview.R; 18 | import com.allen.recyclerview.entry.Home; 19 | import com.chad.library.adapter.base.BaseQuickAdapter; 20 | import com.chad.library.adapter.base.BaseViewHolder; 21 | 22 | import java.util.List; 23 | 24 | /** 25 | * 文 件 名: HomeAdapter 26 | * 创 建 人: Allen 27 | * 创建日期: 16/10/29 13:15 28 | * 邮 箱: AllenCoder@126.com 29 | * 修改时间: 30 | * 修改备注: 31 | */ 32 | public class HomeAdapter extends BaseQuickAdapter { 33 | public HomeAdapter(final List data) { 34 | super(R.layout.item_activity, data); 35 | } 36 | 37 | public HomeAdapter(final int layoutResId, final List data) { 38 | super(R.layout.item_activity, data); 39 | } 40 | 41 | @Override 42 | protected void convert(final BaseViewHolder baseViewHolder, final Home home) { 43 | baseViewHolder.setText(R.id.tv_activity_title, home.Name); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /app/src/main/java/com/allen/recyclerview/adapter/HorizationAdapter.java: -------------------------------------------------------------------------------- 1 | package com.allen.recyclerview.adapter; 2 | 3 | import android.content.Context; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | import android.widget.LinearLayout; 8 | 9 | import com.allen.recyclerview.R; 10 | import com.allen.recyclerview.data.DataServer; 11 | import com.allen.recyclerview.entry.News; 12 | import com.chad.library.adapter.base.BaseQuickAdapter; 13 | import com.chad.library.adapter.base.BaseViewHolder; 14 | 15 | import static com.allen.recyclerview.R.layout.item; 16 | 17 | /** 18 | * https://github.com/CymChad/BaseRecyclerViewAdapterHelper 19 | */ 20 | public class HorizationAdapter extends BaseQuickAdapter { 21 | private LayoutInflater layoutInflater; 22 | private int N ; 23 | 24 | public HorizationAdapter(Context mContex, int N) { 25 | super(item, DataServer.getNews()); 26 | this.N =N; 27 | layoutInflater =LayoutInflater.from(mContex); 28 | } 29 | public HorizationAdapter(Context mContex, int N,int X) { 30 | super(item, DataServer.getNews(X)); 31 | this.N =N; 32 | layoutInflater =LayoutInflater.from(mContex); 33 | } 34 | 35 | 36 | @Override 37 | protected void convert(final BaseViewHolder newsViewHolder, final News news) { 38 | newsViewHolder.setText(R.id.tv_title,news.title); 39 | // newsViewHolder.addOnClickListener(R.id.btn_go); 40 | } 41 | @Override 42 | protected View getItemView(final int layoutResId, final ViewGroup parent) { 43 | View view = layoutInflater.inflate(R.layout.item_news_title, parent, false); 44 | view.setMinimumWidth(parent.getWidth() / N); 45 | LinearLayout.LayoutParams parms = new LinearLayout.LayoutParams(parent.getWidth() / N, ViewGroup.LayoutParams.MATCH_PARENT); 46 | view.setLayoutParams(parms); 47 | return view; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /app/src/main/java/com/allen/recyclerview/adapter/OptimeizeClickAdapter.java: -------------------------------------------------------------------------------- 1 | package com.allen.recyclerview.adapter; 2 | 3 | import com.allen.recyclerview.R; 4 | import com.allen.recyclerview.data.DataServer; 5 | import com.allen.recyclerview.entry.Status; 6 | import com.chad.library.adapter.base.BaseQuickAdapter; 7 | import com.chad.library.adapter.base.BaseViewHolder; 8 | 9 | /** 10 | * https://github.com/CymChad/BaseRecyclerViewAdapterHelper 11 | */ 12 | public class OptimeizeClickAdapter extends BaseQuickAdapter { 13 | public OptimeizeClickAdapter() { 14 | super(R.layout.item_optimeize, DataServer.getSampleData(100)); 15 | } 16 | 17 | public OptimeizeClickAdapter(int dataSize) { 18 | super(R.layout.item_optimeize, DataServer.getSampleData(dataSize)); 19 | } 20 | 21 | @Override 22 | protected void convert(BaseViewHolder helper, Status item) { 23 | // helper.getConvertView().setBackgroundResource(R.drawable.card_click); 24 | // helper 25 | // .addOnClickListener(R.id.button) 26 | // .addOnClickListener(R.id.button2) 27 | // .addOnClickListener(R.id.button3) 28 | // .addOnClickListener(R.id.button4) 29 | // .addOnClickListener(R.id.button5) 30 | // .addOnClickListener(R.id.button6) 31 | // .addOnClickListener(R.id.button7) 32 | // .addOnClickListener(R.id.button8) 33 | // .addOnClickListener(R.id.button9) 34 | // .addOnClickListener(R.id.button10) 35 | // .addOnClickListener(R.id.button11) 36 | // .addOnClickListener(R.id.button12) 37 | // .addOnClickListener(R.id.button13) 38 | // .addOnClickListener(R.id.button14) 39 | // .addOnClickListener(R.id.button15) 40 | // .addOnClickListener(R.id.button16) 41 | // .addOnClickListener(R.id.button17) 42 | // .addOnClickListener(R.id.button18) 43 | // .addOnClickListener(R.id.button19) 44 | // .addOnClickListener(R.id.button20) 45 | // .addOnClickListener(R.id.button21) 46 | // .addOnClickListener(R.id.button22) 47 | // .addOnClickListener(R.id.button23) 48 | // .addOnClickListener(R.id.button25) 49 | // .addOnClickListener(R.id.button26) 50 | // .addOnClickListener(R.id.button27) 51 | // .addOnClickListener(R.id.button28) 52 | // .addOnClickListener(R.id.button29) 53 | // .addOnClickListener(R.id.button30) 54 | // .addOnClickListener(R.id.button31) 55 | // .addOnClickListener(R.id.button32) 56 | // .addOnClickListener(R.id.button33) 57 | // .addOnClickListener(R.id.button34) 58 | // .addOnClickListener(R.id.button35) 59 | // .addOnClickListener(R.id.button36) 60 | // 61 | // ; 62 | // Glide.with(mContext).load(item.getUserAvatar()).crossFade().placeholder(R.mipmap.def_head).transform(new GlideCircleTransform(mContext)).into((ImageView) helper.getView(R.id.tweetAvatar)); 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /app/src/main/java/com/allen/recyclerview/adapter/OptimeizeGridItemClickAdapter.java: -------------------------------------------------------------------------------- 1 | package com.allen.recyclerview.adapter; 2 | 3 | import com.allen.recyclerview.R; 4 | import com.allen.recyclerview.data.DataServer; 5 | import com.allen.recyclerview.entry.Status; 6 | import com.chad.library.adapter.base.BaseQuickAdapter; 7 | import com.chad.library.adapter.base.BaseViewHolder; 8 | 9 | /** 10 | * https://github.com/CymChad/BaseRecyclerViewAdapterHelper 11 | */ 12 | public class OptimeizeGridItemClickAdapter extends BaseQuickAdapter { 13 | public OptimeizeGridItemClickAdapter() { 14 | super(R.layout.item_optimeize, DataServer.getSampleData(100)); 15 | } 16 | 17 | public OptimeizeGridItemClickAdapter(int dataSize) { 18 | super(R.layout.item_optimeize, DataServer.getSampleData(dataSize)); 19 | } 20 | 21 | @Override 22 | protected void convert(BaseViewHolder helper, Status item) { 23 | // helper.getConvertView().setBackgroundResource(R.drawable.card_click); 24 | 25 | 26 | ; 27 | // Glide.with(mContext).load(item.getUserAvatar()).crossFade().placeholder(R.mipmap.def_head).transform(new GlideCircleTransform(mContext)).into((ImageView) helper.getView(R.id.tweetAvatar)); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /app/src/main/java/com/allen/recyclerview/adapter/QuickClickAdapter.java: -------------------------------------------------------------------------------- 1 | package com.allen.recyclerview.adapter; 2 | 3 | import com.allen.recyclerview.R; 4 | import com.allen.recyclerview.data.DataServer; 5 | import com.allen.recyclerview.entry.Status; 6 | import com.chad.library.adapter.base.BaseQuickAdapter; 7 | import com.chad.library.adapter.base.BaseViewHolder; 8 | 9 | /** 10 | * https://github.com/CymChad/BaseRecyclerViewAdapterHelper 11 | */ 12 | public class QuickClickAdapter extends BaseQuickAdapter { 13 | public QuickClickAdapter() { 14 | super(R.layout.item, DataServer.getSampleData(100)); 15 | } 16 | 17 | public QuickClickAdapter(int dataSize) { 18 | super(R.layout.item, DataServer.getSampleData(dataSize)); 19 | } 20 | 21 | @Override 22 | protected void convert(BaseViewHolder helper, Status item) { 23 | // helper.getConvertView().setBackgroundResource(R.drawable.card_click); 24 | helper.setText(R.id.tweetName, item.getUserName()) 25 | .setText(R.id.tweetText, item.getText()) 26 | .setText(R.id.tweetDate, item.getCreatedAt()) 27 | .setVisible(R.id.tweetRT, item.isRetweet()) 28 | .addOnClickListener(R.id.tweetAvatar) 29 | .addOnClickListener(R.id.tweetName) 30 | .addOnLongClickListener(R.id.tweetText) 31 | ; 32 | // Glide.with(mContext).load(item.getUserAvatar()).crossFade().placeholder(R.mipmap.def_head).transform(new GlideCircleTransform(mContext)).into((ImageView) helper.getView(R.id.tweetAvatar)); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /app/src/main/java/com/allen/recyclerview/adapter/RefreshAdapter.java: -------------------------------------------------------------------------------- 1 | package com.allen.recyclerview.adapter; 2 | 3 | import android.support.v7.widget.RecyclerView; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | 8 | import com.allen.recyclerview.R; 9 | import com.allen.recyclerview.entry.News; 10 | 11 | import java.util.List; 12 | 13 | /** 14 | * Created by Allen on 2017/3/24. 15 | */ 16 | 17 | public class RefreshAdapter extends RecyclerView.Adapter { 18 | private List list; 19 | 20 | public RefreshAdapter(List list) { 21 | this.list = list; 22 | } 23 | 24 | @Override 25 | public MyViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) { 26 | View v = LayoutInflater.from(viewGroup.getContext()) 27 | .inflate(R.layout.text_row_item, viewGroup, false); 28 | 29 | return new MyViewHolder(v); 30 | } 31 | 32 | @Override 33 | public void onBindViewHolder(MyViewHolder holder, int position) { 34 | } 35 | 36 | @Override 37 | public int getItemCount() { 38 | return list.size(); 39 | } 40 | public static class MyViewHolder extends RecyclerView.ViewHolder{ 41 | 42 | public MyViewHolder(View itemView) { 43 | super(itemView); 44 | } 45 | } 46 | 47 | // 48 | // public static class MyViewHolder extends RecyclerView.ViewHolder implements AnimateViewHolder { 49 | // 50 | // public ImageView imageView; 51 | // public MyViewHolder(View itemView) { 52 | // super(itemView); 53 | // } 54 | // 55 | // @Override 56 | // public void preAnimateRemoveImpl(RecyclerView.ViewHolder holder) { 57 | // 58 | // } 59 | // 60 | // @Override 61 | // public void animateRemoveImpl(RecyclerView.ViewHolder holder, ViewPropertyAnimatorListener listener) { 62 | // ViewCompat.animate(itemView) 63 | // .translationY(-itemView.getHeight() * 0.3f) 64 | // .alpha(0) 65 | // .setDuration(300) 66 | // .setListener(listener) 67 | // .start(); 68 | // } 69 | // 70 | // @Override 71 | // public void preAnimateAddImpl(RecyclerView.ViewHolder holder) { 72 | // ViewCompat.setTranslationY(itemView, -itemView.getHeight() * 0.3f); 73 | // ViewCompat.setAlpha(itemView, 0); 74 | // } 75 | // 76 | // @Override 77 | // public void animateAddImpl(RecyclerView.ViewHolder holder, ViewPropertyAnimatorListener listener) { 78 | // ViewCompat.animate(itemView) 79 | // .translationY(0) 80 | // .alpha(1) 81 | // .setDuration(300) 82 | // .setListener(listener) 83 | // .start(); 84 | // } 85 | // } 86 | } 87 | -------------------------------------------------------------------------------- /app/src/main/java/com/allen/recyclerview/component/CanvasView.java: -------------------------------------------------------------------------------- 1 | package com.allen.recyclerview.component; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.graphics.Canvas; 6 | import android.graphics.Color; 7 | import android.graphics.Matrix; 8 | import android.graphics.Paint; 9 | import android.util.AttributeSet; 10 | import android.view.MotionEvent; 11 | import android.view.View; 12 | 13 | import com.allen.recyclerview.R; 14 | 15 | /** 16 | * TODO: document your custom view class. 17 | */ 18 | public class CanvasView extends View { 19 | 20 | public CanvasView(Context context) { 21 | super(context); 22 | init(null, 0); 23 | } 24 | 25 | public CanvasView(Context context, AttributeSet attrs) { 26 | super(context, attrs); 27 | init(attrs, 0); 28 | } 29 | 30 | public CanvasView(Context context, AttributeSet attrs, int defStyle) { 31 | super(context, attrs, defStyle); 32 | init(attrs, defStyle); 33 | } 34 | 35 | private void init(AttributeSet attrs, int defStyle) { 36 | // Load attributes 37 | final TypedArray a = getContext().obtainStyledAttributes( 38 | attrs, R.styleable.CanvasView, defStyle, 0); 39 | 40 | a.recycle(); 41 | mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); 42 | mPaint.setStrokeWidth(10); 43 | mPaint.setColor(Color.RED); 44 | 45 | } 46 | 47 | private Paint mPaint; 48 | 49 | @Override 50 | protected void onDraw(Canvas canvas) { 51 | super.onDraw(canvas); 52 | // canvas.drawCircle(getWidth()/2-80,getHeight()/2-60,100,mPaint); 53 | // 54 | // canvas.drawRect(getWidth()/2-220,getHeight()/2+50,getWidth()/2+20,getHeight()/2+250,mPaint); 55 | Matrix matrix = new Matrix(); 56 | matrix = new Matrix(); 57 | matrix.postScale(2, 2); 58 | // canvas.save(); 59 | canvas.setMatrix(matrix); 60 | mPaint.setColor(Color.RED); 61 | // canvas.concat(matrix); 62 | canvas.drawRect(100, 100, 300, 300, mPaint); 63 | // canvas.restore(); 64 | mPaint.setColor(Color.YELLOW); 65 | canvas.drawRect(300, 300, 500, 500, mPaint); 66 | canvas.drawText("canvas.setMatrix(matrix)", 50, 600, mPaint); 67 | } 68 | 69 | @Override 70 | public boolean onTouchEvent(final MotionEvent event) { 71 | switch (event.getAction()) { 72 | 73 | } 74 | return super.onTouchEvent(event); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /app/src/main/java/com/allen/recyclerview/data/DataServer.java: -------------------------------------------------------------------------------- 1 | package com.allen.recyclerview.data; 2 | 3 | 4 | import com.allen.recyclerview.entry.MarryInfo; 5 | import com.allen.recyclerview.entry.News; 6 | import com.allen.recyclerview.entry.Status; 7 | 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | /** 12 | * https://github.com/CymChad/BaseRecyclerViewAdapterHelper 13 | */ 14 | public class DataServer { 15 | 16 | private static final String HTTPS_AVATARS1_GITHUBUSERCONTENT_COM_LINK = "https://avatars1.githubusercontent.com/u/7698209?v=3&s=460"; 17 | private static final String CYM_CHAD = "CymChad"; 18 | 19 | private DataServer() { 20 | } 21 | 22 | public static List getSampleData(int lenth) { 23 | List list = new ArrayList<>(); 24 | for (int i = 0; i < lenth; i++) { 25 | Status status = new Status(); 26 | status.setUserName("Chad" + i); 27 | status.setCreatedAt("04/05/" + i); 28 | status.setRetweet(i % 2 == 0); 29 | status.setUserAvatar("https://avatars1.githubusercontent.com/u/7698209?v=3&s=460"); 30 | status.setText("BaseRecyclerViewAdpaterHelper https://www.recyclerview.org"); 31 | list.add(status); 32 | } 33 | return list; 34 | } 35 | 36 | public static List getNews() { 37 | List list = new ArrayList<>(); 38 | News news = new News("头条"); 39 | list.add(news); 40 | news = new News("热点"); 41 | list.add(news); 42 | news = new News("精选"); 43 | list.add(news); 44 | news = new News("上海"); 45 | list.add(news); 46 | news = new News("财经"); 47 | list.add(news); 48 | news = new News("科技"); 49 | list.add(news); 50 | news = new News("段子"); 51 | list.add(news); 52 | news = new News("视频"); 53 | list.add(news); 54 | news = new News("网易"); 55 | list.add(news); 56 | news = new News("图片"); 57 | list.add(news); 58 | news = new News("直播"); 59 | list.add(news); 60 | news = new News("汽车"); 61 | list.add(news); 62 | for (int i = 0; i < 1000; i++) { 63 | news = new News("汽车"+i); 64 | list.add(news); 65 | } 66 | return list; 67 | } 68 | public static List getNews(int j) { 69 | List list = new ArrayList<>(); 70 | News news = new News("头条"); 71 | // list.add(news); 72 | // news = new News("热点"); 73 | // list.add(news); 74 | // news = new News("精选"); 75 | // list.add(news); 76 | // news = new News("上海"); 77 | // list.add(news); 78 | // news = new News("财经"); 79 | // list.add(news); 80 | // news = new News("科技"); 81 | // list.add(news); 82 | // news = new News("段子"); 83 | // list.add(news); 84 | // news = new News("视频"); 85 | // list.add(news); 86 | // news = new News("网易"); 87 | // list.add(news); 88 | // news = new News("图片"); 89 | // list.add(news); 90 | // news = new News("直播"); 91 | // list.add(news); 92 | // news = new News("汽车"); 93 | list.add(news); 94 | for (int i = 0; i < j; i++) { 95 | news = new News("汽车"+i); 96 | list.add(news); 97 | } 98 | return list; 99 | } 100 | public static List getMarray(int j) { 101 | List list = new ArrayList<>(); 102 | for (int i = 0; i < j; i++) { 103 | MarryInfo news = new MarryInfo("小明","137****5872",true,true); 104 | list.add(news); 105 | } 106 | 107 | return list; 108 | } 109 | 110 | public static List addData(List list, int dataSize) { 111 | for (int i = 0; i < dataSize; i++) { 112 | Status status = new Status(); 113 | status.setUserName("Chad" + i); 114 | status.setCreatedAt("04/05/" + i); 115 | status.setRetweet(i % 2 == 0); 116 | status.setUserAvatar("https://avatars1.githubusercontent.com/u/7698209?v=3&s=460"); 117 | status.setText("Powerful and flexible RecyclerAdapter https://github.com/CymChad/BaseRecyclerViewAdapterHelper"); 118 | list.add(status); 119 | } 120 | 121 | return list; 122 | } 123 | 124 | 125 | } 126 | -------------------------------------------------------------------------------- /app/src/main/java/com/allen/recyclerview/entry/Home.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************* Copyright (c)*********************************\ 3 | ** 4 | ** (c) Copyright 2015, Allen, china, shanghai 5 | ** All Rights Reserved 6 | ** 7 | ** 8 | ** 9 | **-----------------------------------版本信息------------------------------------ 10 | ** 版 本: V0.1 11 | ** 12 | **------------------------------------------------------------------------------ 13 | ********************************End of Head************************************\ 14 | */ 15 | package com.allen.recyclerview.entry; 16 | 17 | /** 18 | * 文 件 名: Home 19 | * 创 建 人: Allen 20 | * 创建日期: 16/10/29 13:15 21 | * 邮 箱: AllenCoder@126.com 22 | * 修改时间: 23 | * 修改备注: 24 | */ 25 | public class Home { 26 | public Home(final String name) { 27 | Name = name; 28 | } 29 | 30 | public String Name; 31 | } 32 | -------------------------------------------------------------------------------- /app/src/main/java/com/allen/recyclerview/entry/MarryInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************* Copyright (c)*********************************\ 3 | ** 4 | ** (c) Copyright 2015, Allen, china, shanghai 5 | ** All Rights Reserved 6 | ** 7 | ** 8 | ** 9 | **-----------------------------------版本信息------------------------------------ 10 | ** 版 本: V0.1 11 | ** 12 | **------------------------------------------------------------------------------ 13 | ********************************End of Head************************************\ 14 | */ 15 | package com.allen.recyclerview.entry; 16 | 17 | /** 18 | * 文 件 名: MarryInfo 19 | * 创 建 人: Allen 20 | * 创建日期: 17/1/6 22:44 21 | * 邮 箱: AllenCoder@126.com 22 | * 修改时间: 23 | * 修改备注: 24 | */ 25 | public class MarryInfo { 26 | 27 | private String name; 28 | private String phone; 29 | private boolean isRepeat; 30 | private boolean isValid; 31 | public boolean isShow=false; 32 | 33 | 34 | public MarryInfo(final String name, final String phone, final boolean isRepeat, final boolean isValid) { 35 | this.name = name; 36 | this.phone = phone; 37 | this.isRepeat = isRepeat; 38 | this.isValid = isValid; 39 | } 40 | 41 | public String getName() { 42 | return name; 43 | } 44 | 45 | public void setName(final String name) { 46 | this.name = name; 47 | } 48 | 49 | public String getPhone() { 50 | return phone; 51 | } 52 | 53 | public void setPhone(final String phone) { 54 | this.phone = phone; 55 | } 56 | 57 | public boolean isRepeat() { 58 | return isRepeat; 59 | } 60 | 61 | public void setRepeat(final boolean repeat) { 62 | isRepeat = repeat; 63 | } 64 | 65 | public boolean isValid() { 66 | return isValid; 67 | } 68 | 69 | public void setValid(final boolean valid) { 70 | isValid = valid; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /app/src/main/java/com/allen/recyclerview/entry/News.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************* Copyright (c)*********************************\ 3 | ** 4 | ** (c) Copyright 2015, Allen, china, shanghai 5 | ** All Rights Reserved 6 | ** 7 | ** 8 | ** 9 | **-----------------------------------版本信息------------------------------------ 10 | ** 版 本: V0.1 11 | ** 12 | **------------------------------------------------------------------------------ 13 | ********************************End of Head************************************\ 14 | */ 15 | package com.allen.recyclerview.entry; 16 | 17 | /** 18 | * 文 件 名: Home 19 | * 创 建 人: Allen 20 | * 创建日期: 16/10/29 13:15 21 | * 邮 箱: AllenCoder@126.com 22 | * 修改时间: 23 | * 修改备注: 24 | */ 25 | public class News { 26 | public News(final String title) { 27 | this.title = title; 28 | } 29 | 30 | public String title; 31 | } 32 | -------------------------------------------------------------------------------- /app/src/main/java/com/allen/recyclerview/entry/Status.java: -------------------------------------------------------------------------------- 1 | package com.allen.recyclerview.entry; 2 | 3 | /** 4 | * https://github.com/CymChad/BaseRecyclerViewAdapterHelper 5 | */ 6 | public class Status { 7 | private boolean isRetweet; 8 | private String text; 9 | private String userName; 10 | private String userAvatar; 11 | private String createdAt; 12 | 13 | public boolean isRetweet() { 14 | return isRetweet; 15 | } 16 | 17 | public void setRetweet(boolean retweet) { 18 | isRetweet = retweet; 19 | } 20 | 21 | public String getText() { 22 | return text; 23 | } 24 | 25 | public void setText(String text) { 26 | this.text = text; 27 | } 28 | 29 | public String getUserName() { 30 | return userName; 31 | } 32 | 33 | public void setUserName(String userName) { 34 | this.userName = userName; 35 | } 36 | 37 | public String getUserAvatar() { 38 | return userAvatar; 39 | } 40 | 41 | public void setUserAvatar(String userAvatar) { 42 | this.userAvatar = userAvatar; 43 | } 44 | 45 | public String getCreatedAt() { 46 | return createdAt; 47 | } 48 | 49 | public void setCreatedAt(String createdAt) { 50 | this.createdAt = createdAt; 51 | } 52 | 53 | @Override 54 | public String toString() { 55 | return "Status{" + 56 | "isRetweet=" + isRetweet + 57 | ", text='" + text + '\'' + 58 | ", userName='" + userName + '\'' + 59 | ", userAvatar='" + userAvatar + '\'' + 60 | ", createdAt='" + createdAt + '\'' + 61 | '}'; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /app/src/main/java/com/allen/recyclerview/view/ScrollByView.java: -------------------------------------------------------------------------------- 1 | package com.allen.recyclerview.view; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.graphics.Canvas; 6 | import android.support.v4.view.ViewCompat; 7 | import android.util.AttributeSet; 8 | import android.view.MotionEvent; 9 | import android.view.VelocityTracker; 10 | import android.view.ViewConfiguration; 11 | import android.widget.FrameLayout; 12 | import android.widget.OverScroller; 13 | 14 | import com.allen.recyclerview.R; 15 | import com.chad.library.adapter.base.util.TouchEventUtil; 16 | import com.orhanobut.logger.Logger; 17 | 18 | public class ScrollByView extends FrameLayout { 19 | 20 | 21 | private int mLastX; 22 | private int mLastY; 23 | private boolean mDragging; 24 | private float mDownX; 25 | private float mDownY; 26 | private int mScaledMinimumFlingVelocity; 27 | private int mScaledMaximumFlingVelocity; 28 | private int mScaledTouchSlop; 29 | private OverScroller mScroller; 30 | public ScrollByView(Context context) { 31 | super(context); 32 | init(null, 0); 33 | } 34 | 35 | public ScrollByView(Context context, AttributeSet attrs) { 36 | super(context, attrs); 37 | init(attrs, 0); 38 | } 39 | 40 | public ScrollByView(Context context, AttributeSet attrs, int defStyle) { 41 | super(context, attrs, defStyle); 42 | init(attrs, defStyle); 43 | } 44 | 45 | private void init(AttributeSet attrs, int defStyle) { 46 | // Load attributes 47 | final TypedArray a = getContext().obtainStyledAttributes( 48 | attrs, R.styleable.ScrollByView, defStyle, 0); 49 | 50 | ViewConfiguration configuration = ViewConfiguration.get(getContext()); 51 | mScaledTouchSlop = configuration.getScaledTouchSlop(); 52 | mScaledMinimumFlingVelocity = configuration.getScaledMinimumFlingVelocity(); 53 | mScaledMaximumFlingVelocity = configuration.getScaledMaximumFlingVelocity(); 54 | mScroller = new OverScroller(getContext()); 55 | a.recycle(); 56 | 57 | } 58 | 59 | @Override 60 | public boolean onInterceptTouchEvent(MotionEvent ev) { 61 | // boolean isIntercepted = super.onInterceptTouchEvent(ev); 62 | // int action = ev.getAction(); 63 | // switch (action) { 64 | // case MotionEvent.ACTION_DOWN: { 65 | // mDownX = mLastX = (int) ev.getX(); 66 | // mDownY = (int) ev.getY(); 67 | // return false; 68 | // } 69 | // case MotionEvent.ACTION_MOVE: { 70 | // int disX = (int) (ev.getX() - mDownX); 71 | // int disY = (int) (ev.getY() - mDownY); 72 | // return Math.abs(disX) > mScaledTouchSlop && Math.abs(disX) > Math.abs(disY); 73 | // } 74 | // case MotionEvent.ACTION_UP: { 75 | // 76 | // return false; 77 | // } 78 | // case MotionEvent.ACTION_CANCEL: { 79 | // if (!mScroller.isFinished()) 80 | // mScroller.abortAnimation(); 81 | // return false; 82 | // } 83 | // } 84 | return true; 85 | } 86 | @Override 87 | protected void onDraw(Canvas canvas) { 88 | super.onDraw(canvas); 89 | } 90 | private VelocityTracker mVelocityTracker; 91 | @Override 92 | public boolean onTouchEvent(MotionEvent ev) { 93 | Logger.d( TouchEventUtil.getTouchAction(ev.getAction())); 94 | if (mVelocityTracker == null) mVelocityTracker = VelocityTracker.obtain(); 95 | mVelocityTracker.addMovement(ev); 96 | int dx; 97 | int dy; 98 | int action = ev.getAction(); 99 | switch (action) { 100 | case MotionEvent.ACTION_DOWN: { 101 | mLastX = (int) ev.getX(); 102 | mLastY = (int) ev.getY(); 103 | break; 104 | } 105 | case MotionEvent.ACTION_MOVE: { 106 | int disX = (int) (mLastX - ev.getX()); 107 | int disY = (int) (mLastY - ev.getY()); 108 | if (!mDragging && Math.abs(disX) > mScaledTouchSlop && Math.abs(disX) > Math.abs(disY)) { 109 | mDragging = true; 110 | } 111 | // scrollBy(disX, 0); 112 | // getChildAt(1).layout(-disX,disY,-disX+200,disY+200); 113 | getChildAt(0).layout(disX,disY,disX+200,disY+200); 114 | // getChildAt(0).layout(disX,disY,disX+200,disY+200); 115 | // scrollBy(disX, 0); 116 | // if (mDragging) { 117 | // scrollBy(disX, 0); 118 | // mLastX = (int) ev.getX(); 119 | // mLastY = (int) ev.getY(); 120 | // } 121 | break; 122 | } 123 | case MotionEvent.ACTION_UP: { 124 | dx = (int) (mDownX - ev.getX()); 125 | dy = (int) (mDownY - ev.getY()); 126 | mDragging = false; 127 | mVelocityTracker.computeCurrentVelocity(1000, mScaledMaximumFlingVelocity); 128 | int velocityX = (int) mVelocityTracker.getXVelocity(); 129 | int velocity = Math.abs(velocityX); 130 | if (velocity > mScaledMinimumFlingVelocity) { 131 | ViewCompat.postInvalidateOnAnimation(this); 132 | } else { 133 | // judgeOpenClose(dx, dy); 134 | } 135 | getChildAt(0).layout(dx+velocityX,dy+velocity,dx+velocityX+200,dy+velocity+200); 136 | mVelocityTracker.clear(); 137 | mVelocityTracker.recycle(); 138 | mVelocityTracker = null; 139 | if (Math.abs(mDownX - ev.getX()) > mScaledTouchSlop 140 | || Math.abs(mDownY - ev.getY()) > mScaledTouchSlop 141 | ) { 142 | ev.setAction(MotionEvent.ACTION_CANCEL); 143 | super.onTouchEvent(ev); 144 | return true; 145 | } 146 | break; 147 | } 148 | case MotionEvent.ACTION_CANCEL: { 149 | mDragging = false; 150 | if (!mScroller.isFinished()) { 151 | mScroller.abortAnimation(); 152 | } else { 153 | dx = (int) (mDownX - ev.getX()); 154 | dy = (int) (mDownY - ev.getY()); 155 | } 156 | break; 157 | } 158 | } 159 | 160 | return super.onTouchEvent(ev); 161 | } 162 | 163 | } 164 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v21/touch_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/selector_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/selector_item_child.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/touch_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_custom_view.xml: -------------------------------------------------------------------------------- 1 | 2 | 14 | 25 | 33 | 34 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_hide.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_horizontal_adjust.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 14 | 18 | 25 | 29 | 36 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_list.xml: -------------------------------------------------------------------------------- 1 | 2 | 14 | 15 | 16 | 17 | 21 | 22 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_local_refresh.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 29 | 30 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 18 | 19 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_optimize_item_click.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 13 | 14 | 20 | 21 | 22 | 23 | 24 | 25 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_recycler_click.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 12 | 13 | 20 | 21 |