├── .gitignore ├── .idea ├── codeStyles │ └── Project.xml ├── encodings.xml ├── gradle.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── wellijohn │ │ └── org │ │ └── scrollviewwithstickview │ │ ├── AndroidWidgetActivity.java │ │ ├── LinearLayoutManagerUnScrollable.java │ │ ├── Main2Activity.java │ │ ├── MainActivity.java │ │ ├── adapter │ │ ├── RVRightListAdapter.java │ │ ├── ReListAdapter.java │ │ └── TabFragmentAdapter.java │ │ ├── constant │ │ └── Constant.java │ │ ├── fragment │ │ ├── ChildRecyclerViewFragment.java │ │ ├── ChildScrollViewFragment.java │ │ ├── LazyFragment.java │ │ ├── NoScrollWebView.java │ │ └── RecyclerViewFragment.java │ │ └── listener │ │ └── OnRVItemClickListener.java │ └── res │ ├── drawable-v24 │ └── ic_launcher_foreground.xml │ ├── drawable-xxhdpi │ └── food.jpg │ ├── drawable │ ├── btn_border_gray_999_bg.xml │ ├── btn_green_big_nomal_bg.xml │ ├── btn_yellow_full_small_corner_bg.xml │ └── ic_launcher_background.xml │ ├── layout │ ├── activity_android_widget.xml │ ├── activity_main.xml │ ├── activity_main2.xml │ ├── demo_child_scroll.xml │ ├── just_recyclerview.xml │ ├── recyclerview.xml │ ├── rv_item.xml │ ├── rv_rightitem.xml │ └── title.xml │ ├── mipmap-anydpi-v26 │ ├── ic_launcher.xml │ └── ic_launcher_round.xml │ ├── mipmap-hdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-mdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ └── values │ ├── arrays.xml │ ├── colors.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── imgs ├── QR_code_258 .png ├── scrollsnap.gif ├── snapshot2.gif └── 仿饿了么列表页.gif ├── settings.gradle └── stickscrollview ├── .gitignore ├── build.gradle ├── jcenter.gradle ├── proguard-rules.pro └── src └── main ├── AndroidManifest.xml ├── java └── wellijohn │ └── org │ └── scrollviewwithstickheader │ ├── ChildRecyclerView.java │ ├── ChildScrollView.java │ ├── ChildWebView.java │ ├── Constant.java │ ├── ScrollViewWithStickHeader.java │ ├── layoutmanager │ ├── NoSlideGridLayoutManager.java │ └── NoSlideLinearLayoutManager.java │ └── utils │ ├── UIUtil.java │ └── ViewUtil.java └── res └── values ├── attrs.xml └── strings.xml /.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/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 15 | 16 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16 | 26 | 27 | 28 | 29 | 30 | 31 | 33 | 34 | 35 | 36 | 37 | 1.8 38 | 39 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | **前言,一天在点外卖的时候,注意到饿了么列表页的滑动效果不错,但是觉得其中的手势滑动还是挺复杂的,正好又碰到了在熟悉Touch事件的理解当中,所以就抽空对着饿了么的列表页面尝试写写这个效果,同时增加了双列表的联动效果** 2 | ** 在实现上述效果之后,用了下appbarlayout,觉得也能实现上述滑动的效果,不需要更改什么代码,体验上更好,具体可以看AndroidWidgetActivity,在这里面就是CollapsingToolbarLayout和appbarlayout的使用,完成上述的效果,可以简单看下实现的效果图,如果你们觉得满足需求了就不需要继续往下看了,如果想了解下手势点击原理的话,欢迎往下看提点意见:** 3 | 4 | ## APK下载地址 5 | ![stickscrollview](https://github.com/WelliJohn/StickScrollView/blob/master/imgs/QR_code_258%20.png?raw=true) 6 | ## 1.先贴一个实现的效果图 7 | ![image](https://github.com/WelliJohn/StickScrollView/blob/master/imgs/%E4%BB%BF%E9%A5%BF%E4%BA%86%E4%B9%88%E5%88%97%E8%A1%A8%E9%A1%B5.gif?raw=true) 8 | 9 | 10 | ## 2.引入 11 | ``` 12 | allprojects { 13 | repositories { 14 | jcenter() 15 | maven { url "https://jitpack.io" } 16 | } 17 | } 18 | 19 | dependencies { 20 |    com.github.WelliJohn:StickScrollView:1.1.7 21 | } 22 | ``` 23 | 24 | ## 3.界面的布局说明 25 | ``` 26 | 30 | 31 | 38 | //这里是header部分,可以随便自定义 39 | 40 | 41 | 46 | 47 | 54 | 55 | 59 | 60 | 61 | 62 | ``` 63 | 比如我们看到的仿饿了么的列表页界面,我们就需要在ViewPager设置Fragment,fragment中是左右两个列表,看下fragment的xml设置: 64 | ``` 65 | 66 | 71 | 72 | 78 | 79 | 85 | 86 | ``` 87 | 88 | ## 4.java代码必要设置 89 | ``` 90 | mStickScrollView.setContentView(mLLStickList);//这个是必须的,mLLStickList就是你想到这个布局再滑动就是下面列表滑动的部分了。 91 | mStickScrollView.setSuspensionView(mViewBottom);//这个是底部的悬浮布局,如果没有可以不设置 92 | ``` 93 | 94 | ## 5.注意事项 95 | * ScrollViewWithStickHeader内部目前支持放置ViewPager,ScrollView,RecyclerView,WebView 96 | * ScrollView,RecyclerView,WebView需要对应使用ChildScrollView,ChildRecyclerView,ChildWebView 97 | * 我们在使用的时候,需要调用mStickScrollView.setContentView(mContentView);mLLStickList就是我们需要StickHeader+列表的部分,如果你没有StickHeader的话,那么直接设置列表进来也可以,总之,你想滑动到哪个位置接下来滑动就是单纯下面的部分滑动,那你就把下面的View整体设置为mContentView。刚刚那个的ContentView是id为ll_stick_list的View。 98 | * 另外在这里ScrollViewWithStickHeader增加autoscroll属性,默认是关闭的,如果autoscroll:true的话,在我们手指放开的时候,contentView会判断是否自动滑动到顶部还是隐藏不见。 99 | * 暂不支持weight的使用,因为weight会进行二次绘制,所以如果要实现底部bottom的话,请用RelativeiLayout 100 | * 如果是用RecyclerView的话,LinearLayoutManager需要继承NoSlideLinearLayoutManager,GridLayoutManager需要继承NoSlideGridLayoutManager,new NoSlideLinearLayoutManager(context)。 101 | 102 | ![自动滚动的效果图](https://github.com/WelliJohn/StickScrollView/blob/master/imgs/scrollsnap.gif?raw=true) 103 | 104 | 105 | 106 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 28 5 | defaultConfig { 6 | applicationId "wellijohn.org.scrollviewwithstickview" 7 | minSdkVersion 14 8 | targetSdkVersion 28 9 | versionCode 5 10 | versionName "1.4" 11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | 20 | lintOptions { 21 | abortOnError false 22 | } 23 | 24 | } 25 | 26 | dependencies { 27 | implementation fileTree(include: ['*.jar'], dir: 'libs') 28 | implementation 'com.android.support:appcompat-v7:27.1.1' 29 | implementation 'com.android.support.constraint:constraint-layout:1.1.2' 30 | implementation 'com.android.support:recyclerview-v7:27.1.1' 31 | implementation project(':stickscrollview') 32 | // implementation 'com.github.WelliJohn:StickScrollView:1.1.7' 33 | // compile 'wellijohn.org.tvanim:animtv:1.0.0' 34 | implementation 'com.android.support:design:27.1.1' 35 | 36 | // implementation 'com.github.WelliJohn:StickScrollView:0.0.1' 37 | 38 | } 39 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /app/src/main/java/wellijohn/org/scrollviewwithstickview/AndroidWidgetActivity.java: -------------------------------------------------------------------------------- 1 | package wellijohn.org.scrollviewwithstickview; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.design.widget.AppBarLayout; 6 | import android.support.design.widget.CollapsingToolbarLayout; 7 | import android.support.design.widget.TabLayout; 8 | import android.support.v4.view.ViewPager; 9 | import android.support.v7.app.AppCompatActivity; 10 | import android.support.v7.widget.Toolbar; 11 | import android.widget.ImageView; 12 | 13 | import wellijohn.org.scrollviewwithstickview.adapter.TabFragmentAdapter; 14 | 15 | /** 16 | * @author: JiangWeiwei 17 | * @time: 2018/8/2-10:05 18 | * @email: jiangweiwei@qccr.com 19 | * @desc: 20 | */ 21 | public class AndroidWidgetActivity extends AppCompatActivity { 22 | private AppBarLayout mAppBar; 23 | private CollapsingToolbarLayout mToolbarLayout; 24 | private ImageView mImageview; 25 | private Toolbar mToolbar; 26 | private TabLayout mTablayout; 27 | private ViewPager mVp; 28 | private TabFragmentAdapter mTabFragmentAdapter; 29 | 30 | @Override 31 | protected void onCreate(@Nullable Bundle savedInstanceState) { 32 | super.onCreate(savedInstanceState); 33 | setContentView(R.layout.activity_android_widget); 34 | initView(); 35 | initUI(); 36 | } 37 | 38 | private void initUI() { 39 | mTabFragmentAdapter = new TabFragmentAdapter(getSupportFragmentManager()); 40 | mVp.setAdapter(mTabFragmentAdapter); 41 | mVp.addOnPageChangeListener( 42 | new TabLayout.TabLayoutOnPageChangeListener(mTablayout)); 43 | mVp.setOffscreenPageLimit(3); 44 | mTablayout.setupWithViewPager(mVp); 45 | } 46 | 47 | private void initView() { 48 | mAppBar = findViewById(R.id.app_bar); 49 | mToolbarLayout = findViewById(R.id.toolbar_layout); 50 | mImageview = findViewById(R.id.imageview); 51 | mToolbar = findViewById(R.id.toolbar); 52 | mTablayout = findViewById(R.id.tablayout); 53 | mVp = findViewById(R.id.viewpage); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /app/src/main/java/wellijohn/org/scrollviewwithstickview/LinearLayoutManagerUnScrollable.java: -------------------------------------------------------------------------------- 1 | package wellijohn.org.scrollviewwithstickview; 2 | 3 | import android.content.Context; 4 | import android.support.v7.widget.LinearLayoutManager; 5 | import android.support.v7.widget.RecyclerView; 6 | import android.util.AttributeSet; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | 10 | 11 | public class LinearLayoutManagerUnScrollable extends LinearLayoutManager { 12 | private int[] mMeasuredDimension = new int[2]; 13 | 14 | public LinearLayoutManagerUnScrollable(Context context) { 15 | super(context); 16 | setAutoMeasureEnabled(false); 17 | } 18 | 19 | public LinearLayoutManagerUnScrollable(Context context, int orientation, boolean reverseLayout) { 20 | super(context, orientation, reverseLayout); 21 | setAutoMeasureEnabled(false); 22 | } 23 | 24 | public LinearLayoutManagerUnScrollable(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 25 | super(context, attrs, defStyleAttr, defStyleRes); 26 | setAutoMeasureEnabled(false); 27 | } 28 | 29 | @Override 30 | public void onMeasure(RecyclerView.Recycler recycler, RecyclerView.State state, int widthSpec, int heightSpec) { 31 | final int widthMode = View.MeasureSpec.getMode(widthSpec); 32 | final int heightMode = View.MeasureSpec.getMode(heightSpec); 33 | final int widthSize = View.MeasureSpec.getSize(widthSpec); 34 | final int heightSize = View.MeasureSpec.getSize(heightSpec); 35 | 36 | int width = 0; 37 | int height = 0; 38 | for (int i = 0; i < getItemCount(); i++) { 39 | measureScrapChild(recycler, i, View.MeasureSpec.makeMeasureSpec(i, View.MeasureSpec.UNSPECIFIED), 40 | View.MeasureSpec.makeMeasureSpec(i, View.MeasureSpec.UNSPECIFIED), mMeasuredDimension); 41 | if (getOrientation() == HORIZONTAL) { 42 | width = width + mMeasuredDimension[0]; 43 | if (i == 0) { 44 | height = mMeasuredDimension[1]; 45 | } 46 | } else { 47 | height = height + mMeasuredDimension[1]; 48 | if (i == 0) { 49 | width = mMeasuredDimension[0]; 50 | } 51 | } 52 | } 53 | 54 | switch (widthMode) { 55 | case View.MeasureSpec.EXACTLY: 56 | width = widthSize; 57 | break; 58 | case View.MeasureSpec.AT_MOST: 59 | case View.MeasureSpec.UNSPECIFIED: 60 | } 61 | 62 | switch (heightMode) { 63 | case View.MeasureSpec.EXACTLY: 64 | height = heightSize; 65 | break; 66 | case View.MeasureSpec.AT_MOST: 67 | case View.MeasureSpec.UNSPECIFIED: 68 | } 69 | 70 | setMeasuredDimension(width, height); 71 | } 72 | 73 | private void measureScrapChild(RecyclerView.Recycler recycler, int position, int widthSpec, 74 | int heightSpec, int[] measuredDimension) { 75 | try { 76 | View view = recycler.getViewForPosition(position);//Warning 动态添加时报IndexOutOfBoundsException 77 | 78 | if (view != null) { 79 | RecyclerView.LayoutParams p = (RecyclerView.LayoutParams) view.getLayoutParams(); 80 | 81 | int childWidthSpec = ViewGroup.getChildMeasureSpec(widthSpec, 82 | getPaddingLeft() + getPaddingRight(), p.width); 83 | 84 | int childHeightSpec = ViewGroup.getChildMeasureSpec(heightSpec, 85 | getPaddingTop() + getPaddingBottom(), p.height); 86 | 87 | view.measure(childWidthSpec, childHeightSpec); 88 | measuredDimension[0] = view.getMeasuredWidth() + p.leftMargin + p.rightMargin; 89 | measuredDimension[1] = view.getMeasuredHeight() + p.bottomMargin + p.topMargin; 90 | recycler.recycleView(view); 91 | } 92 | } catch (Exception e) { 93 | e.printStackTrace(); 94 | } finally { 95 | } 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /app/src/main/java/wellijohn/org/scrollviewwithstickview/Main2Activity.java: -------------------------------------------------------------------------------- 1 | package wellijohn.org.scrollviewwithstickview; 2 | 3 | import android.support.v7.app.AppCompatActivity; 4 | import android.os.Bundle; 5 | 6 | public class Main2Activity extends AppCompatActivity { 7 | 8 | @Override 9 | protected void onCreate(Bundle savedInstanceState) { 10 | super.onCreate(savedInstanceState); 11 | setContentView(R.layout.activity_main2); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /app/src/main/java/wellijohn/org/scrollviewwithstickview/MainActivity.java: -------------------------------------------------------------------------------- 1 | package wellijohn.org.scrollviewwithstickview; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.support.design.widget.TabLayout; 6 | import android.support.v4.view.ViewPager; 7 | import android.support.v7.app.AppCompatActivity; 8 | import android.support.v7.widget.RecyclerView; 9 | import android.view.View; 10 | import android.webkit.WebSettings; 11 | import android.webkit.WebView; 12 | import android.widget.Button; 13 | import android.widget.LinearLayout; 14 | import android.widget.ScrollView; 15 | import android.widget.TextView; 16 | 17 | import wellijohn.org.scrollviewwithstickheader.ChildRecyclerView; 18 | import wellijohn.org.scrollviewwithstickheader.ChildScrollView; 19 | import wellijohn.org.scrollviewwithstickheader.ScrollViewWithStickHeader; 20 | import wellijohn.org.scrollviewwithstickview.adapter.ReListAdapter; 21 | import wellijohn.org.scrollviewwithstickview.adapter.TabFragmentAdapter; 22 | 23 | public class MainActivity extends AppCompatActivity { 24 | 25 | private TextView mTvStickHeader; 26 | private ScrollView mScrollviewChild; 27 | private RecyclerView mRv; 28 | private ReListAdapter mReListAdapter; 29 | 30 | private static final String TAG = "MainActivity"; 31 | private TabLayout mOrderManagerTabs; 32 | private ChildScrollView mCsv; 33 | private ViewPager mVp; 34 | private TabFragmentAdapter mTabFragmentAdapter; 35 | private WebView mWebview; 36 | private LinearLayout mLLStickList; 37 | private Button mButton; 38 | private ScrollViewWithStickHeader mStickScrollView; 39 | private LinearLayout mLl; 40 | private ChildRecyclerView mCrv; 41 | private View mViewBottom; 42 | 43 | @Override 44 | protected void onCreate(Bundle savedInstanceState) { 45 | super.onCreate(savedInstanceState); 46 | setContentView(R.layout.activity_main); 47 | initView(); 48 | initUI(); 49 | mStickScrollView.setContentView(mLLStickList); 50 | mStickScrollView.setSuspensionView(mViewBottom); 51 | 52 | startActivity(new Intent(this,AndroidWidgetActivity.class)); 53 | } 54 | 55 | private void initUI() { 56 | 57 | mTabFragmentAdapter = new TabFragmentAdapter(getSupportFragmentManager()); 58 | mVp.setAdapter(mTabFragmentAdapter); 59 | mVp.addOnPageChangeListener( 60 | new TabLayout.TabLayoutOnPageChangeListener(mOrderManagerTabs)); 61 | mVp.setOffscreenPageLimit(3); 62 | mOrderManagerTabs.setupWithViewPager(mVp); 63 | WebSettings webSettings = mWebview.getSettings(); 64 | //设置WebView属性,能够执行Javascript脚本 65 | webSettings.setJavaScriptEnabled(true); 66 | mWebview.loadUrl("https://segmentfault.com/u/wellijhon_58622d2f61c2d"); 67 | 68 | // Log.d(TAG, "initUI: " + (mLl.getDescendantFocusability() == ViewGroup.FOCUS_BLOCK_DESCENDANTS)); 69 | } 70 | 71 | private void initView() { 72 | // mTvStickHeader = (TextView) findViewById(R.id.tv_stick_header); 73 | mOrderManagerTabs = (TabLayout) findViewById(R.id.order_manager_tabs); 74 | // mCsv = (ChildScrollView) findViewById(R.id.csv); 75 | mVp = (ViewPager) findViewById(R.id.vp); 76 | mLLStickList = (LinearLayout) findViewById(R.id.ll_stick_list); 77 | 78 | mWebview = (WebView) findViewById(R.id.webview); 79 | mButton = (Button) findViewById(R.id.button); 80 | mStickScrollView = (ScrollViewWithStickHeader) findViewById(R.id.stick_scroll_view); 81 | mLl = (LinearLayout) findViewById(R.id.ll); 82 | mViewBottom = (View) findViewById(R.id.tv_bottom); 83 | // mCrv = (ChildRecyclerView) findViewById(R.id.crv); 84 | 85 | 86 | } 87 | 88 | } 89 | -------------------------------------------------------------------------------- /app/src/main/java/wellijohn/org/scrollviewwithstickview/adapter/RVRightListAdapter.java: -------------------------------------------------------------------------------- 1 | package wellijohn.org.scrollviewwithstickview.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 | import android.widget.ImageView; 8 | import android.widget.TextView; 9 | import android.widget.Toast; 10 | 11 | import wellijohn.org.scrollviewwithstickview.R; 12 | import wellijohn.org.scrollviewwithstickview.constant.Constant; 13 | 14 | /** 15 | * @author: JiangWeiwei 16 | * @time: 2017/11/3-18:12 17 | * @email: 18 | * @desc: 19 | */ 20 | public class RVRightListAdapter extends RecyclerView.Adapter { 21 | 22 | 23 | 24 | 25 | 26 | @Override 27 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 28 | View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.rv_rightitem, parent, false); 29 | return new ViewHolder(view); 30 | } 31 | 32 | @Override 33 | public void onBindViewHolder(ViewHolder holder, int position) { 34 | holder.tv.setText(Constant.foods[position]); 35 | holder.iv.setImageResource(R.drawable.food); 36 | holder.itemView.setOnClickListener(new View.OnClickListener() { 37 | @Override 38 | public void onClick(View v) { 39 | Toast.makeText(v.getContext(),"点击了",Toast.LENGTH_LONG).show(); 40 | } 41 | }); 42 | } 43 | 44 | @Override 45 | public int getItemCount() { 46 | return Constant.foods.length; 47 | } 48 | 49 | final class ViewHolder extends RecyclerView.ViewHolder { 50 | 51 | TextView tv; 52 | ImageView iv; 53 | 54 | 55 | public ViewHolder(View itemView) { 56 | super(itemView); 57 | tv = (TextView) itemView.findViewById(R.id.tv); 58 | iv = (ImageView) itemView.findViewById(R.id.iv); 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /app/src/main/java/wellijohn/org/scrollviewwithstickview/adapter/ReListAdapter.java: -------------------------------------------------------------------------------- 1 | package wellijohn.org.scrollviewwithstickview.adapter; 2 | 3 | import android.graphics.Color; 4 | import android.support.v7.widget.RecyclerView; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.widget.TextView; 9 | 10 | import wellijohn.org.scrollviewwithstickview.R; 11 | import wellijohn.org.scrollviewwithstickview.listener.OnRVItemClickListener; 12 | 13 | /** 14 | * @author: JiangWeiwei 15 | * @time: 2017/11/3-18:12 16 | * @email: 17 | * @desc: 18 | */ 19 | public class ReListAdapter extends RecyclerView.Adapter { 20 | 21 | 22 | private String[] foods = {"米饭", "招牌菜", "家常风味", "精美甜品", "饮料", "田园时蔬", "美食", 23 | "米饭", "招牌菜", "家常风味", "精美甜品", "饮料", "田园时蔬", "美食"}; 24 | 25 | private OnRVItemClickListener onRVItemClickListener; 26 | 27 | private int selectIndex; 28 | 29 | @Override 30 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 31 | View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.rv_item, parent, false); 32 | return new ViewHolder(view); 33 | } 34 | 35 | @Override 36 | public void onBindViewHolder(final ViewHolder holder, final int position) { 37 | holder.tv.setText(foods[position]); 38 | if (position == selectIndex) { 39 | holder.itemView.setBackgroundColor(Color.parseColor("#FFFFFF")); 40 | } else { 41 | holder.itemView.setBackgroundColor(Color.parseColor("#EEEEEE")); 42 | } 43 | 44 | holder.itemView.setOnClickListener(new View.OnClickListener() { 45 | @Override 46 | public void onClick(View v) { 47 | if (onRVItemClickListener != null) 48 | onRVItemClickListener.onClick(foods[holder.getAdapterPosition()], 49 | holder.getAdapterPosition()); 50 | selectIndex = position; 51 | notifyDataSetChanged(); 52 | } 53 | }); 54 | 55 | } 56 | 57 | public void setOnRVItemClickListener(OnRVItemClickListener onRVItemClickListener) { 58 | this.onRVItemClickListener = onRVItemClickListener; 59 | } 60 | 61 | @Override 62 | public int getItemCount() { 63 | return foods.length; 64 | } 65 | 66 | public void setSelectIndex(int newLeftPos) { 67 | selectIndex = newLeftPos; 68 | notifyDataSetChanged(); 69 | } 70 | 71 | final class ViewHolder extends RecyclerView.ViewHolder { 72 | 73 | TextView tv; 74 | 75 | 76 | public ViewHolder(View itemView) { 77 | super(itemView); 78 | tv = (TextView) itemView.findViewById(R.id.tv); 79 | 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /app/src/main/java/wellijohn/org/scrollviewwithstickview/adapter/TabFragmentAdapter.java: -------------------------------------------------------------------------------- 1 | package wellijohn.org.scrollviewwithstickview.adapter; 2 | 3 | import android.support.annotation.Nullable; 4 | import android.support.v4.app.Fragment; 5 | import android.support.v4.app.FragmentManager; 6 | import android.support.v4.app.FragmentPagerAdapter; 7 | 8 | import wellijohn.org.scrollviewwithstickview.fragment.RecyclerViewFragment; 9 | 10 | /** 11 | * @author: JiangWeiwei 12 | * @time: 2017/11/9-11:33 13 | * @email: 14 | * @desc: 15 | */ 16 | public class TabFragmentAdapter extends FragmentPagerAdapter { 17 | 18 | public TabFragmentAdapter(FragmentManager fm) { 19 | super(fm); 20 | } 21 | 22 | @Override 23 | public Fragment getItem(int position) { 24 | // return ChildRecyclerViewFragment.newInstance(position); 25 | return RecyclerViewFragment.newInstance(position); 26 | } 27 | 28 | @Override 29 | public int getCount() { 30 | return 3; 31 | } 32 | 33 | @Nullable 34 | @Override 35 | public CharSequence getPageTitle(int position) { 36 | if (position == 0) { 37 | return "点餐"; 38 | } 39 | if (position == 1) { 40 | return "评价"; 41 | } 42 | if (position == 2) { 43 | return "商家"; 44 | } 45 | return "tab" + position; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /app/src/main/java/wellijohn/org/scrollviewwithstickview/constant/Constant.java: -------------------------------------------------------------------------------- 1 | package wellijohn.org.scrollviewwithstickview.constant; 2 | 3 | /** 4 | * @author: JiangWeiwei 5 | * @time: 2018/3/22-9:24 6 | * @email: jiangweiwei@qccr.com 7 | * @desc: 8 | */ 9 | public class Constant { 10 | 11 | public static final String KEY_TAG = "KEY_TAG"; 12 | public static final String[] foods = {"糖醋里脊1", "酸辣土豆丝2", "豆腐3", "上汤菠菜4", "红烧肉5" 13 | , "茶树菇6", "干菜刀豆7", "开背虾8", "清炖牛肉9", "红烧鱼块10", "红烧肉11", "茶树菇12" 14 | , "茶树菇13", "干菜刀豆14", "开背虾15", "清炖牛肉16", "红烧鱼块17", "红烧肉18", "茶树菇19" 15 | // , "茶树菇6", "干菜刀豆7", "开背虾8", "清炖牛肉9", "红烧鱼块10", "红烧肉11", "茶树菇12" 16 | // , "茶树菇13", "干菜刀豆14", "开背虾15", "清炖牛肉16", "红烧鱼块17", "红烧肉18", "茶树菇19" 17 | // , "茶树菇6", "干菜刀豆7", "开背虾8", "清炖牛肉9", "红烧鱼块10", "红烧肉11", "茶树菇12" 18 | // , "茶树菇13", "干菜刀豆14", "开背虾15", "清炖牛肉16", "红烧鱼块17", "红烧肉18", "茶树菇19" 19 | // , "茶树菇6", "干菜刀豆7", "开背虾8", "清炖牛肉9", "红烧鱼块10", "红烧肉11", "茶树菇12" 20 | // , "茶树菇13", "干菜刀豆14", "开背虾15", "清炖牛肉16", "红烧鱼块17", "红烧肉18", "茶树菇19" 21 | // , "茶树菇6", "干菜刀豆7", "开背虾8", "清炖牛肉9", "红烧鱼块10", "红烧肉11", "茶树菇12" 22 | // , "茶树菇13", "干菜刀豆14", "开背虾15", "清炖牛肉16", "红烧鱼块17", "红烧肉18", "茶树菇19" 23 | // , "茶树菇6", "干菜刀豆7", "开背虾8", "清炖牛肉9", "红烧鱼块10", "红烧肉11", "茶树菇12" 24 | // , "茶树菇13", "干菜刀豆14", "开背虾15", "清炖牛肉16", "红烧鱼块17", "红烧肉18", "茶树菇19" 25 | // , "茶树菇6", "干菜刀豆7", "开背虾8", "清炖牛肉9", "红烧鱼块10", "红烧肉11", "茶树菇12" 26 | // , "茶树菇13", "干菜刀豆14", "开背虾15", "清炖牛肉16", "红烧鱼块17", "红烧肉18", "茶树菇19" 27 | // , "茶树菇6", "干菜刀豆7", "开背虾8", "清炖牛肉9", "红烧鱼块10", "红烧肉11", "茶树菇12" 28 | // , "茶树菇13", "干菜刀豆14", "开背虾15", "清炖牛肉16", "红烧鱼块17", "红烧肉18", "茶树菇19" 29 | // , "茶树菇6", "干菜刀豆7", "开背虾8", "清炖牛肉9", "红烧鱼块10", "红烧肉11", "茶树菇12" 30 | // , "茶树菇13", "干菜刀豆14", "开背虾15", "清炖牛肉16", "红烧鱼块17", "红烧肉18", "茶树菇19" 31 | // , "茶树菇6", "干菜刀豆7", "开背虾8", "清炖牛肉9", "红烧鱼块10", "红烧肉11", "茶树菇12" 32 | // , "茶树菇13", "干菜刀豆14", "开背虾15", "清炖牛肉16", "红烧鱼块17", "红烧肉18", "茶树菇19" 33 | // , "茶树菇6", "干菜刀豆7", "开背虾8", "清炖牛肉9", "红烧鱼块10", "红烧肉11", "茶树菇12" 34 | // , "茶树菇13", "干菜刀豆14", "开背虾15", "清炖牛肉16", "红烧鱼块17", "红烧肉18", "茶树菇19" 35 | // , "茶树菇6", "干菜刀豆7", "开背虾8", "清炖牛肉9", "红烧鱼块10", "红烧肉11", "茶树菇12" 36 | // , "茶树菇13", "干菜刀豆14", "开背虾15", "清炖牛肉16", "红烧鱼块17", "红烧肉18", "茶树菇19" 37 | // , "茶树菇13", "干菜刀豆14", "开背虾15", "清炖牛肉16", "红烧鱼块17", "红烧肉18", "茶树菇19" 38 | // , "茶树菇6", "干菜刀豆7", "开背虾8", "清炖牛肉9", "红烧鱼块10", "红烧肉11", "茶树菇12" 39 | // , "茶树菇13", "干菜刀豆14", "开背虾15", "清炖牛肉16", "红烧鱼块17", "红烧肉18", "茶树菇19" 40 | // , "茶树菇6", "干菜刀豆7", "开背虾8", "清炖牛肉9", "红烧鱼块10", "红烧肉11", "茶树菇12" 41 | // , "茶树菇13", "干菜刀豆14", "开背虾15", "清炖牛肉16", "红烧鱼块17", "红烧肉18", "茶树菇19" 42 | // , "茶树菇6", "干菜刀豆7", "开背虾8", "清炖牛肉9", "红烧鱼块10", "红烧肉11", "茶树菇12" 43 | // , "茶树菇13", "干菜刀豆14", "开背虾15", "清炖牛肉16", "红烧鱼块17", "红烧肉18", "茶树菇19" 44 | // , "茶树菇6", "干菜刀豆7", "开背虾8", "清炖牛肉9", "红烧鱼块10", "红烧肉11", "茶树菇12" 45 | // , "茶树菇13", "干菜刀豆14", "开背虾15", "清炖牛肉16", "红烧鱼块17", "红烧肉18", "茶树菇19" 46 | // , "茶树菇6", "干菜刀豆7", "开背虾8", "清炖牛肉9", "红烧鱼块10", "红烧肉11", "茶树菇12" 47 | // , "茶树菇13", "干菜刀豆14", "开背虾15", "清炖牛肉16", "红烧鱼块17", "红烧肉18", "茶树菇19" 48 | // , "茶树菇6", "干菜刀豆7", "开背虾8", "清炖牛肉9", "红烧鱼块10", "红烧肉11", "茶树菇12" 49 | // , "茶树菇13", "干菜刀豆14", "开背虾15", "清炖牛肉16", "红烧鱼块17", "红烧肉18", "茶树菇19" 50 | // , "茶树菇6", "干菜刀豆7", "开背虾8", "清炖牛肉9", "红烧鱼块10", "红烧肉11", "茶树菇12" 51 | // , "茶树菇13", "干菜刀豆14", "开背虾15", "清炖牛肉16", "红烧鱼块17", "红烧肉18", "茶树菇19" 52 | // , "茶树菇6", "干菜刀豆7", "开背虾8", "清炖牛肉9", "红烧鱼块10", "红烧肉11", "茶树菇12" 53 | // , "茶树菇13", "干菜刀豆14", "开背虾15", "清炖牛肉16", "红烧鱼块17", "红烧肉18", "茶树菇19" 54 | // , "茶树菇6", "干菜刀豆7", "开背虾8", "清炖牛肉9", "红烧鱼块10", "红烧肉11", "茶树菇12" 55 | // , "茶树菇13", "干菜刀豆14", "开背虾15", "清炖牛肉16", "红烧鱼块17", "红烧肉18", "茶树菇19" 56 | // , "茶树菇6", "干菜刀豆7", "开背虾8", "清炖牛肉9", "红烧鱼块10", "红烧肉11", "茶树菇12" 57 | // , "茶树菇13", "干菜刀豆14", "开背虾15", "清炖牛肉16", "红烧鱼块17", "红烧肉18", "茶树菇19" 58 | // , "茶树菇6", "干菜刀豆7", "开背虾8", "清炖牛肉9", "红烧鱼块10", "红烧肉11", "茶树菇12" 59 | // , "茶树菇13", "干菜刀豆14", "开背虾15", "清炖牛肉16", "红烧鱼块17", "红烧肉18", "茶树菇19" 60 | // , "茶树菇13", "干菜刀豆14", "开背虾15", "清炖牛肉16", "红烧鱼块17", "红烧肉18", "茶树菇19" 61 | // , "茶树菇6", "干菜刀豆7", "开背虾8", "清炖牛肉9", "红烧鱼块10", "红烧肉11", "茶树菇12" 62 | // , "茶树菇13", "干菜刀豆14", "开背虾15", "清炖牛肉16", "红烧鱼块17", "红烧肉18", "茶树菇19" 63 | // , "茶树菇6", "干菜刀豆7", "开背虾8", "清炖牛肉9", "红烧鱼块10", "红烧肉11", "茶树菇12" 64 | // , "茶树菇13", "干菜刀豆14", "开背虾15", "清炖牛肉16", "红烧鱼块17", "红烧肉18", "茶树菇19" 65 | // , "茶树菇6", "干菜刀豆7", "开背虾8", "清炖牛肉9", "红烧鱼块10", "红烧肉11", "茶树菇12" 66 | // , "茶树菇13", "干菜刀豆14", "开背虾15", "清炖牛肉16", "红烧鱼块17", "红烧肉18", "茶树菇19" 67 | // , "茶树菇6", "干菜刀豆7", "开背虾8", "清炖牛肉9", "红烧鱼块10", "红烧肉11", "茶树菇12" 68 | // , "茶树菇13", "干菜刀豆14", "开背虾15", "清炖牛肉16", "红烧鱼块17", "红烧肉18", "茶树菇19" 69 | // , "茶树菇6", "干菜刀豆7", "开背虾8", "清炖牛肉9", "红烧鱼块10", "红烧肉11", "茶树菇12" 70 | // , "茶树菇13", "干菜刀豆14", "开背虾15", "清炖牛肉16", "红烧鱼块17", "红烧肉18", "茶树菇19" 71 | // , "茶树菇6", "干菜刀豆7", "开背虾8", "清炖牛肉9", "红烧鱼块10", "红烧肉11", "茶树菇12" 72 | // , "茶树菇13", "干菜刀豆14", "开背虾15", "清炖牛肉16", "红烧鱼块17", "红烧肉18", "茶树菇19" 73 | // , "茶树菇6", "干菜刀豆7", "开背虾8", "清炖牛肉9", "红烧鱼块10", "红烧肉11", "茶树菇12" 74 | // , "茶树菇13", "干菜刀豆14", "开背虾15", "清炖牛肉16", "红烧鱼块17", "红烧肉18", "茶树菇19" 75 | // , "茶树菇6", "干菜刀豆7", "开背虾8", "清炖牛肉9", "红烧鱼块10", "红烧肉11", "茶树菇12" 76 | // , "茶树菇13", "干菜刀豆14", "开背虾15", "清炖牛肉16", "红烧鱼块17", "红烧肉18", "茶树菇19" 77 | // , "茶树菇13", "干菜刀豆14", "开背虾15", "清炖牛肉16", "红烧鱼块17", "红烧肉18", "茶树菇19" 78 | // , "茶树菇6", "干菜刀豆7", "开背虾8", "清炖牛肉9", "红烧鱼块10", "红烧肉11", "茶树菇12" 79 | // , "茶树菇13", "干菜刀豆14", "开背虾15", "清炖牛肉16", "红烧鱼块17", "红烧肉18", "茶树菇19" 80 | // , "茶树菇6", "干菜刀豆7", "开背虾8", "清炖牛肉9", "红烧鱼块10", "红烧肉11", "茶树菇12" 81 | // , "茶树菇13", "干菜刀豆14", "开背虾15", "清炖牛肉16", "红烧鱼块17", "红烧肉18", "茶树菇19" 82 | // , "茶树菇6", "干菜刀豆7", "开背虾8", "清炖牛肉9", "红烧鱼块10", "红烧肉11", "茶树菇12" 83 | // , "茶树菇13", "干菜刀豆14", "开背虾15", "清炖牛肉16", "红烧鱼块17", "红烧肉18", "茶树菇19" 84 | // , "茶树菇6", "干菜刀豆7", "开背虾8", "清炖牛肉9", "红烧鱼块10", "红烧肉11", "茶树菇12" 85 | // , "茶树菇13", "干菜刀豆14", "开背虾15", "清炖牛肉16", "红烧鱼块17", "红烧肉18", "茶树菇19" 86 | // , "茶树菇6", "干菜刀豆7", "开背虾8", "清炖牛肉9", "红烧鱼块10", "红烧肉11", "茶树菇12" 87 | // , "茶树菇13", "干菜刀豆14", "开背虾15", "清炖牛肉16", "红烧鱼块17", "红烧肉18", "茶树菇19" 88 | // , "茶树菇6", "干菜刀豆7", "开背虾8", "清炖牛肉9", "红烧鱼块10", "红烧肉11", "茶树菇12" 89 | // , "茶树菇13", "干菜刀豆14", "开背虾15", "清炖牛肉16", "红烧鱼块17", "红烧肉18", "茶树菇19" 90 | // , "茶树菇6", "干菜刀豆7", "开背虾8", "清炖牛肉9", "红烧鱼块10", "红烧肉11", "茶树菇12" 91 | // , "茶树菇13", "干菜刀豆14", "开背虾15", "清炖牛肉16", "红烧鱼块17", "红烧肉18", "茶树菇19" 92 | // , "茶树菇6", "干菜刀豆7", "开背虾8", "清炖牛肉9", "红烧鱼块10", "红烧肉11", "茶树菇12" 93 | // , "茶树菇13", "干菜刀豆14", "开背虾15", "清炖牛肉16", "红烧鱼块17", "红烧肉18", "茶树菇19" 94 | // , "茶树菇6", "干菜刀豆7", "开背虾8", "清炖牛肉9", "红烧鱼块10", "红烧肉11", "茶树菇12" 95 | // , "茶树菇13", "干菜刀豆14", "开背虾15", "清炖牛肉16", "红烧鱼块17", "红烧肉18", "茶树菇19" 96 | // , "茶树菇6", "干菜刀豆7", "开背虾8", "清炖牛肉9", "红烧鱼块10", "红烧肉11", "茶树菇12" 97 | // , "茶树菇13", "干菜刀豆14", "开背虾15", "清炖牛肉16", "红烧鱼块17", "红烧肉18", "茶树菇19" 98 | // , "茶树菇6", "干菜刀豆7", "开背虾8", "清炖牛肉9", "红烧鱼块10", "红烧肉11", "茶树菇12" 99 | // , "茶树菇13", "干菜刀豆14", "开背虾15", "清炖牛肉16", "红烧鱼块17", "红烧肉18", "茶树菇19" 100 | // , "茶树菇6", "干菜刀豆7", "开背虾8", "清炖牛肉9", "红烧鱼块10", "红烧肉11", "茶树菇12" 101 | // , "茶树菇13", "干菜刀豆14", "开背虾15", "清炖牛肉16", "红烧鱼块17", "红烧肉18", "茶树菇19" 102 | // , "茶树菇6", "干菜刀豆7", "开背虾8", "清炖牛肉9", "红烧鱼块10", "红烧肉11", "茶树菇12" 103 | }; 104 | } 105 | -------------------------------------------------------------------------------- /app/src/main/java/wellijohn/org/scrollviewwithstickview/fragment/ChildRecyclerViewFragment.java: -------------------------------------------------------------------------------- 1 | package wellijohn.org.scrollviewwithstickview.fragment; 2 | 3 | import android.content.Context; 4 | import android.os.Bundle; 5 | import android.support.annotation.NonNull; 6 | import android.support.annotation.Nullable; 7 | import android.support.v4.app.Fragment; 8 | import android.support.v7.widget.LinearLayoutManager; 9 | import android.support.v7.widget.RecyclerView; 10 | import android.view.LayoutInflater; 11 | import android.view.View; 12 | import android.view.ViewGroup; 13 | import android.webkit.WebSettings; 14 | 15 | import wellijohn.org.scrollviewwithstickheader.ChildWebView; 16 | import wellijohn.org.scrollviewwithstickheader.layoutmanager.NoSlideLinearLayoutManager; 17 | import wellijohn.org.scrollviewwithstickview.MainActivity; 18 | import wellijohn.org.scrollviewwithstickview.R; 19 | import wellijohn.org.scrollviewwithstickview.adapter.RVRightListAdapter; 20 | import wellijohn.org.scrollviewwithstickview.adapter.ReListAdapter; 21 | import wellijohn.org.scrollviewwithstickview.listener.OnRVItemClickListener; 22 | 23 | /** 24 | * @author: JiangWeiwei 25 | * @time: 2017/11/9-11:34 26 | * @email: 27 | * @desc: 28 | */ 29 | public class ChildRecyclerViewFragment extends LazyFragment { 30 | private static final String KEY_FRAGMENT_INT = "KEY_FRAGMENT_INT"; 31 | private RecyclerView mChildRecyclerview; 32 | private RecyclerView mChildRecyclerviewRight; 33 | private ReListAdapter mReListAdapter; 34 | private NoSlideLinearLayoutManager mLlRight; 35 | private boolean move; 36 | private boolean mIsLeftTouch = true; 37 | private int mOldLeftIndex; 38 | private RecyclerViewListener mRecyclerViewListener; 39 | private MainActivity mParentActivity; 40 | private ChildWebView webview; 41 | 42 | @Override 43 | public void onAttach(Context context) { 44 | super.onAttach(context); 45 | if (context != null && context instanceof MainActivity) { 46 | mParentActivity = (MainActivity) context; 47 | } 48 | } 49 | 50 | @Nullable 51 | @Override 52 | public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 53 | View view = LayoutInflater.from(container.getContext()).inflate(R.layout.recyclerview, container, false); 54 | initView(view); 55 | return view; 56 | } 57 | 58 | @Override 59 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { 60 | super.onViewCreated(view, savedInstanceState); 61 | // mChildRecyclerviewRight.post(new Runnable() { 62 | // @Override 63 | // public void run() { 64 | // ViewGroup.LayoutParams layoutParams = mChildRecyclerviewRight.getLayoutParams(); 65 | // layoutParams.height = 1400; 66 | // mChildRecyclerviewRight.setLayoutParams(layoutParams); 67 | // } 68 | // }); 69 | 70 | WebSettings settings = webview.getSettings(); 71 | settings.setJavaScriptEnabled(true); 72 | webview.loadUrl("https://www.baidu.com/?tn=22073068_oem_dg"); 73 | } 74 | 75 | 76 | private void initView(View view) { 77 | mChildRecyclerview = (RecyclerView) view.findViewById(R.id.child_recyclerview); 78 | mChildRecyclerviewRight = (RecyclerView) view.findViewById(R.id.child_recyclerview_right); 79 | webview = (ChildWebView) view.findViewById(R.id.webview); 80 | } 81 | 82 | public static Fragment newInstance(int position) { 83 | ChildRecyclerViewFragment fragment = new ChildRecyclerViewFragment(); 84 | Bundle bundle = new Bundle(); 85 | bundle.putInt(KEY_FRAGMENT_INT, position); 86 | fragment.setArguments(bundle); 87 | return fragment; 88 | } 89 | 90 | 91 | class RecyclerViewListener extends RecyclerView.OnScrollListener { 92 | 93 | private int mIndex; 94 | 95 | 96 | @Override 97 | public void onScrolled(RecyclerView recyclerView, int dx, int dy) { 98 | super.onScrolled(recyclerView, dx, dy); 99 | if (!mIsLeftTouch) { 100 | leftLocation(); 101 | } 102 | mIsLeftTouch = false; 103 | } 104 | 105 | 106 | public void setIndex(int index) { 107 | this.mIndex = index; 108 | } 109 | 110 | 111 | private void leftLocation() { 112 | int firstItem = mLlRight.findFirstVisibleItemPosition(); 113 | int newRightPos = firstItem / 2; 114 | if (newRightPos != mOldLeftIndex) { 115 | mReListAdapter.setSelectIndex(newRightPos); 116 | mOldLeftIndex = newRightPos; 117 | } 118 | } 119 | 120 | } 121 | 122 | @Override 123 | void lazyFetchData() { 124 | initUI(); 125 | } 126 | 127 | private void initUI() { 128 | mRecyclerViewListener = new RecyclerViewListener(); 129 | 130 | mLlRight = new NoSlideLinearLayoutManager(getActivity()); 131 | 132 | mReListAdapter = new ReListAdapter(); 133 | LinearLayoutManager ll = new NoSlideLinearLayoutManager(getActivity()); 134 | mChildRecyclerview.setLayoutManager(ll); 135 | mChildRecyclerview.setAdapter(mReListAdapter); 136 | mReListAdapter.setOnRVItemClickListener(new OnRVItemClickListener() { 137 | @Override 138 | public void onClick(String s, int index) { 139 | mIsLeftTouch = true; 140 | if (mOldLeftIndex != index) { 141 | int scrollIndex = index * 2; 142 | mRecyclerViewListener.setIndex(scrollIndex); 143 | mLlRight.scrollToPositionWithOffset(scrollIndex, 0); 144 | mOldLeftIndex = index; 145 | } 146 | } 147 | }); 148 | 149 | 150 | mChildRecyclerviewRight.setLayoutManager(mLlRight); 151 | mChildRecyclerviewRight.setAdapter(new RVRightListAdapter()); 152 | mChildRecyclerviewRight.addOnScrollListener(mRecyclerViewListener); 153 | } 154 | } 155 | -------------------------------------------------------------------------------- /app/src/main/java/wellijohn/org/scrollviewwithstickview/fragment/ChildScrollViewFragment.java: -------------------------------------------------------------------------------- 1 | package wellijohn.org.scrollviewwithstickview.fragment; 2 | 3 | import android.content.Context; 4 | import android.os.Bundle; 5 | import android.support.annotation.NonNull; 6 | import android.support.annotation.Nullable; 7 | import android.support.v4.app.Fragment; 8 | import android.view.LayoutInflater; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | import android.widget.TextView; 12 | import android.widget.Toast; 13 | 14 | import wellijohn.org.scrollviewwithstickview.MainActivity; 15 | import wellijohn.org.scrollviewwithstickview.R; 16 | import wellijohn.org.scrollviewwithstickview.adapter.ReListAdapter; 17 | 18 | /** 19 | * @author: JiangWeiwei 20 | * @time: 2017/11/9-11:34 21 | * @email: 22 | * @desc: 23 | */ 24 | public class ChildScrollViewFragment extends Fragment { 25 | private static final String KEY_FRAGMENT_INT = "KEY_FRAGMENT_INT"; 26 | private ReListAdapter mReListAdapter; 27 | private boolean move; 28 | private boolean mIsLeftTouch = true; 29 | private int mOldLeftIndex; 30 | private MainActivity mParentActivity; 31 | private TextView mTvTitle; 32 | 33 | @Override 34 | public void onAttach(Context context) { 35 | super.onAttach(context); 36 | if (context != null && context instanceof MainActivity) { 37 | mParentActivity = (MainActivity) context; 38 | } 39 | } 40 | 41 | @Nullable 42 | @Override 43 | public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 44 | View view = LayoutInflater.from(container.getContext()).inflate(R.layout.demo_child_scroll, container, false); 45 | initView(view); 46 | mTvTitle.setOnClickListener(new View.OnClickListener() { 47 | @Override 48 | public void onClick(View v) { 49 | Toast.makeText(v.getContext(),"存在点击事件",Toast.LENGTH_LONG).show(); 50 | } 51 | }); 52 | return view; 53 | } 54 | 55 | @Override 56 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { 57 | super.onViewCreated(view, savedInstanceState); 58 | } 59 | 60 | 61 | private void initView(View view) { 62 | mTvTitle = (TextView) view.findViewById(R.id.tv_title); 63 | } 64 | 65 | public static Fragment newInstance(int position) { 66 | ChildScrollViewFragment fragment = new ChildScrollViewFragment(); 67 | Bundle bundle = new Bundle(); 68 | bundle.putInt(KEY_FRAGMENT_INT, position); 69 | fragment.setArguments(bundle); 70 | return fragment; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /app/src/main/java/wellijohn/org/scrollviewwithstickview/fragment/LazyFragment.java: -------------------------------------------------------------------------------- 1 | package wellijohn.org.scrollviewwithstickview.fragment; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v4.app.Fragment; 6 | import android.view.View; 7 | 8 | /** 9 | * @author: JiangWeiwei 10 | * @time: 2018/3/15-12:24 11 | * @email: jiangweiwei@qccr.com 12 | * @desc: 13 | */ 14 | public abstract class LazyFragment extends Fragment { 15 | boolean isViewPrepared; // 标识fragment视图已经初始化完毕 16 | boolean hasFetchData; // 标识已经触发过懒加载数据 17 | 18 | 19 | @Override 20 | public void setUserVisibleHint(boolean isVisibleToUser) { 21 | super.setUserVisibleHint(isVisibleToUser); 22 | if (isVisibleToUser) {//当当前为显示页面时 23 | lazyFetchDataIfPrepared(); 24 | } 25 | } 26 | 27 | @Override 28 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { 29 | super.onViewCreated(view, savedInstanceState); 30 | isViewPrepared = true; 31 | } 32 | 33 | @Override 34 | public void onActivityCreated(@Nullable Bundle savedInstanceState) { 35 | super.onActivityCreated(savedInstanceState); 36 | lazyFetchDataIfPrepared(); 37 | } 38 | 39 | void lazyFetchDataIfPrepared() { 40 | // 用户可见fragment && 没有加载过数据 && 视图已经准备完毕 41 | if (getUserVisibleHint() && !hasFetchData && isViewPrepared) { 42 | hasFetchData = true; //已加载过数据 43 | lazyFetchData(); 44 | } 45 | } 46 | 47 | abstract void lazyFetchData(); 48 | } 49 | -------------------------------------------------------------------------------- /app/src/main/java/wellijohn/org/scrollviewwithstickview/fragment/NoScrollWebView.java: -------------------------------------------------------------------------------- 1 | package wellijohn.org.scrollviewwithstickview.fragment; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.content.Context; 5 | import android.util.AttributeSet; 6 | import android.view.ViewGroup; 7 | import android.webkit.WebView; 8 | 9 | /** 10 | * @author: JiangWeiwei 11 | * @time: 2017/12/1-17:30 12 | * @email: 13 | * @desc: 14 | */ 15 | public class NoScrollWebView extends WebView { 16 | 17 | @SuppressLint("NewApi") 18 | public NoScrollWebView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 19 | super(context, attrs, defStyleAttr, defStyleRes); 20 | } 21 | 22 | public NoScrollWebView(Context context, AttributeSet attrs, int defStyleAttr) { 23 | super(context, attrs, defStyleAttr); 24 | 25 | post(new Runnable() { 26 | @Override 27 | public void run() { 28 | // Log.d(TAG, "WebView的高度run: " + NoScrollWebView.this.getMeasuredHeight()); 29 | ViewGroup.LayoutParams lp =NoScrollWebView.this.getLayoutParams(); 30 | lp.height =3000; 31 | NoScrollWebView.this.setLayoutParams(lp); 32 | } 33 | }); 34 | // setWebViewClient(new WebViewClient() { 35 | // @Override 36 | // public void onPageFinished(WebView view, String url) { 37 | // super.onPageFinished(view, url); 38 | // Log.d(TAG, "WebView的高度run: " + view.getContentHeight()); 39 | // ViewGroup.LayoutParams lp =view.getLayoutParams(); 40 | // lp.height = view.getContentHeight(); 41 | // view.setLayoutParams(lp); 42 | // } 43 | // }); 44 | } 45 | 46 | public NoScrollWebView(Context context, AttributeSet attrs) { 47 | this(context, attrs, 0); 48 | } 49 | 50 | public NoScrollWebView(Context context) { 51 | this(context, null); 52 | } 53 | 54 | @Override 55 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 56 | int mExpandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST); 57 | super.onMeasure(widthMeasureSpec, mExpandSpec); 58 | } 59 | 60 | 61 | } -------------------------------------------------------------------------------- /app/src/main/java/wellijohn/org/scrollviewwithstickview/fragment/RecyclerViewFragment.java: -------------------------------------------------------------------------------- 1 | package wellijohn.org.scrollviewwithstickview.fragment; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.NonNull; 5 | import android.support.annotation.Nullable; 6 | import android.support.v4.app.Fragment; 7 | import android.support.v7.widget.LinearLayoutManager; 8 | import android.support.v7.widget.RecyclerView; 9 | import android.view.LayoutInflater; 10 | import android.view.View; 11 | import android.view.ViewGroup; 12 | 13 | import wellijohn.org.scrollviewwithstickview.R; 14 | import wellijohn.org.scrollviewwithstickview.adapter.RVRightListAdapter; 15 | 16 | /** 17 | * @author: JiangWeiwei 18 | * @time: 2018/8/2-10:36 19 | * @email: jiangweiwei@qccr.com 20 | * @desc: 21 | */ 22 | public class RecyclerViewFragment extends LazyFragment { 23 | private static final String KEY_FRAGMENT_INT = "KEY_FRAGMENT_INT"; 24 | 25 | private RecyclerView mRv; 26 | private RecyclerView mRvRight; 27 | 28 | @Nullable 29 | @Override 30 | public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 31 | View view = LayoutInflater.from(container.getContext()).inflate(R.layout.just_recyclerview, container, false); 32 | initView(view); 33 | return view; 34 | } 35 | 36 | @Override 37 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { 38 | super.onViewCreated(view, savedInstanceState); 39 | mRv.setLayoutManager(new LinearLayoutManager(getActivity())); 40 | mRv.setAdapter(new RVRightListAdapter()); 41 | 42 | mRvRight.setLayoutManager(new LinearLayoutManager(getActivity())); 43 | mRvRight.setAdapter(new RVRightListAdapter()); 44 | } 45 | 46 | @Override 47 | void lazyFetchData() { 48 | // mRv.setLayoutManager(new LinearLayoutManager(getActivity())); 49 | // mRv.setAdapter(new RVRightListAdapter()); 50 | } 51 | 52 | 53 | private void initView(View view) { 54 | mRv = view.findViewById(R.id.rv); 55 | mRvRight = view.findViewById(R.id.rv_right); 56 | } 57 | 58 | public static Fragment newInstance(int position) { 59 | RecyclerViewFragment fragment = new RecyclerViewFragment(); 60 | Bundle bundle = new Bundle(); 61 | bundle.putInt(KEY_FRAGMENT_INT, position); 62 | fragment.setArguments(bundle); 63 | return fragment; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /app/src/main/java/wellijohn/org/scrollviewwithstickview/listener/OnRVItemClickListener.java: -------------------------------------------------------------------------------- 1 | package wellijohn.org.scrollviewwithstickview.listener; 2 | 3 | /** 4 | * @author: JiangWeiwei 5 | * @time: 2018/3/20-10:04 6 | * @email: jiangweiwei@qccr.com 7 | * @desc: 8 | */ 9 | public interface OnRVItemClickListener { 10 | void onClick(T t, int index); 11 | } 12 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/food.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WelliJohn/StickScrollView/8754f660aa4ad2ba5a4b8615dc1b3f34cb21c3bc/app/src/main/res/drawable-xxhdpi/food.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable/btn_border_gray_999_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/btn_green_big_nomal_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/btn_yellow_full_small_corner_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_android_widget.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 14 | 15 | 24 | 25 | 36 | 37 | 42 | 43 | 44 | 52 | 53 | 62 | 63 | 64 | 65 | 70 | 71 | 72 | 73 | 74 | 75 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 15 | 16 | 23 | 24 | 25 | 30 | 31 | 36 | 37 | 41 | 42 | 48 | 49 | 58 | 59 | 60 | 66 | 67 | 72 | 73 | 78 | 79 | 80 | 86 | 87 | 94 | 95 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 111 | 112 | 113 | 120 | 121 | 122 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 145 |